generated from fhdsl/metricminer-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleanalytics.Rmd
132 lines (89 loc) · 7.93 KB
/
googleanalytics.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
title: "Google Analytics"
output:
html_document:
toc: true
toc_float: true
toc_collapsed: true
date: "`r format(Sys.time(), '%d %B, %Y')`"
---
## Preview
```{r, echo = FALSE, hide = TRUE, message = FALSE}
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))
yaml <- yaml::read_yaml(file.path(root_dir, "_config_automation.yml"))
## For google analytics
ga_metrics <- readr::read_tsv(file.path("metricminer_data", "ga", "ga_metrics.tsv"))
ga_dimensions <- readr::read_tsv(file.path("metricminer_data", "ga", "ga_dimensions.tsv"))
ga_link_clicks <- readr::read_tsv(file.path("metricminer_data", "ga", "ga_link_clicks.tsv"))
## For google
# ga_metrics <- googlesheets4::read_sheet(yaml$ga_googlesheet, sheet = "metrics")
# ga_dimensions <- googlesheets4::read_sheet(yaml$ga_googlesheet, sheet = "dimensions")
# ga_link_clicks <- googlesheets4::read_sheet(yaml$ga_googlesheet, sheet = "link_clicks")
```
**Still need to add plots here. Describe below what kinds of plots may work for the data available**
## Data Information
Data information for google analytics metrics (`ga_metrics`):
Most of these metrics involve how users interact with a website or app, specifically in "event" terminology. Events are a means of measuring user interaction and can include actions like loading a page, clicking a link, submitting a form or requesting information, searches, shares content from. Do website creators need to define or add/create events to track for their website or is that automatic?
* `activeUsers`: The number of distinct users who visited your website or application. An active user is any user who visited your website or application. An active user is any user who has an engaged session or when Analytics collects parameters from a website or app indicative of a first time or active user.
* `newUsers`: The number of new unique user IDs that logged the first_open or first_visit event. The metric allows you to measure the number of users who interacted with your site or launched your app for the first time.
* `totalUsers`: The number of unique user IDs that triggered any events. The metric allows you to measure the number of unique users who logged an event.
* `eventCountPerUser`: The average number of events triggered per user. Specifically the event count divided by the number of active users. The event count in turn is the number of times users triggered an event.
* `screenPageViewsPerUser`: The average number of mobile app screens or web pages viewed per user. This would then be the total number of views (`screenPageViews`) divided by the total number of users (`totalUsers`)
* `sessions`: The number of sessions that began on your website or application. A session is a period of time during which a user interacts with your website or app. A session initiates when a user either opens your app in the foreground or views a page or screen and no session is currently active (e.g., their previous session has timed out). By default, a session ends (times out) after 30 minutes of user inactivity. There is no limit to how long a session can last.
* `averageSessionDuration`: The average duration (in seconds) of users' sessions.
* `screenPageViews`: The number of mobile app screens or web pages your users saw. Repeated views of a single screen or page are counted.
* `engagementRate`: The percentage of sessions that were engaged sessions. Specifically, the number of engaged sessions divided by the total number of sessions. An engaged session is a session that lasts 10 seconds or longer or has 1 or more conversion events or 2 or more page or screen views. (A conversion event is any user action that's valuable to your business and is defined by marking the event as a conversion. This is in contrast to most other metrics that are populated automatically.)
```{r}
knitr::kable(ga_metrics)
```
**In the preview section above**: *Add plots that are like Figures 9 and 10 from the ITN evaluation*
Data information for google analytics dimensions (`ga_dimensions`):
* `website`: Indicates the name of the website associated with that session.
* `day`: Indicates the day of the session
* `month`: Indicates the month of the session
* `year`: Indicates the year of the session
* `country`: Indicates the country from which a session originates
* `fullPageURL`: Indicates full page URL of the page that is viewed in that session.
```{r}
knitr::kable(ga_dimensions)
```
**In the preview section above**: *Add a plot that shows a map and distribution of countries? (though this might not generalize well)* or *Add a plot that shows traffic over time*
Data information for google analytics link clicks (`ga_link_clicks`):
* `website`: Indicates the website on which the outbound click event occurred
* `linkURL`: Indicates the URL for the outbound click. What does NA mean for this -- a random click on the website?
```{r}
knitr::kable(ga_link_clicks)
```
## Setting up Google Analytics
Grab information from vignette
## Customization
### Customizing Google Analytics Data
Google Analytics explains that each dimension and metric that can be collected and reported has a scope (user-, session-, or hit-level) and in most cases, only dimensions and metrics that share the same scope can be combined.
To learn more about about Google Analytics in general, [visit the google analytics documentation](https://analytics.google.com/analytics/academy/), and [visit your own dashboard](https://analytics.google.com/analytics/) to customize and explore the possibilites of what you can collect.
### Plots
Review ggplot2 documentation for customization of plots [visit the ggplot2 documentation here](https://ggplot2.tidyverse.org/) or [look at this posit cheatsheet](https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf).
## Setting up Google Analytics
[Follow the steps from the above section to authenticate Google](#setting-up-google-authentication) -- make sure that the account you have authenticated for has access to the Google Analytics properties you wish to collect.
We'll need to collect the Google Analytics property IDs for the websites you want to retrieve data from.
1. Go to https://analytics.google.com/ -- You may have to login. These instructions are assuming you have already set up Google Analytics and have been collecting data.
2. Then click on the website at the top of the navbar. It will bring you to a dropdown that shows all your websites.
<img src = "resources/images/google-analytics-dropdown.png" width = "50%">
4 .Click on one of the websites where you'd like to retrieve data from. The URL will look something like this:
```
https://analytics.google.com/analytics/web/?authuser=1#/p<PROPERTY_ID_HERE>/reports/home
```
5. Copy the property id and put it in the `ga_property_ids:` part of the `_config_automation.yml`.
Repeat these same steps for all the properties you'd like to collect data for, separating the IDs by commas. Delete the example IDs we have put there as placeholders.
```
###### Google Analytics ######
refresh-ga: yes
ga_property_ids: [ 422671031, 422558989 ]
ga_googlesheet:
```
- [ ] In the `config_automation.yml` file, make sure that `refresh-ga` is set to "yes".
- [ ] Optionally, if you are saving data to Google, specify a googlesheet ID in `ga_googlesheet` you'd like the GitHub data to be saved to. This will only be relevant if you've set `data_dest` to `google`.
## Customizing the data
In order to customize the data you are downloading from Google Analytics you can modify the
`refresh-scripts/refresh-ga.R` script in your repository.
You can take a look at the [`metricminer` R package documentation](https://hutchdatascience.org/metricminer/articles/getting-started.html) for more details about the functions and what is possible.
If you have a metric need that is not currently fulfilled by `metricminer` or `metricminer-dashboard` we encourage you to [file a GitHub issue with us and let us know about your new feature idea (or bug report)](https://github.com/fhdsl/metricminer/issues/new/choose).