Skip to content

Instantly share code, notes, and snippets.

@natzir
Created October 8, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natzir/5ff92f4c7c4625c1f4b8a41b56996d6d to your computer and use it in GitHub Desktop.
Save natzir/5ff92f4c7c4625c1f4b8a41b56996d6d to your computer and use it in GitHub Desktop.
---
title: "Causal Impact"
output: causal_impact_notebook
---
```{r}
install.packages("devtools")
install.packages("curl")
install_github("skardhamar/rga")
install.packages("CausalImpact")
```
```{r}
library(devtools)
library(curl)
library(CausalImpact)
library(ggplot2)
library(rga)
```
```{r}
rga.open(instance = "ga")
```
```{r}
id <- ""
ga$getData(id)
```
```{r}
gaData <- ga$getData(id, start.date = as.Date("2017-10-01"),end.date=as.Date("2019-05-30"), metrics = "ga:sessions",dimensions = "ga:date", segment = "gaid::G1FqL1zpQHaaeoBTJlIOxA")
```
```{r}
ggplot(gaData, aes(date, sessions)) + geom_line() +
ylab("Daily Sessions") + theme_bw() +
ggtitle("Organic Sessions")
```
```{r}
pre.period <- as.Date(c("2017-10-01", "2019-02-24"))
post.period <- as.Date(c("2019-02-25", "2019-05-30"))
```
```{r}
impact <- CausalImpact(gaData, pre.period, post.period, model.args = list(niter = 5000))
plot(impact)
summary(impact)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment