https://github.com/gilliganondata/ga-view-audit
Script that cycles through a list of views (view IDs) and makes a snapshot of custom dimension, custom metrics, and goals that it then pushes to an Excel file.
https://github.com/gilliganondata/ga-view-audit
Last synced: about 1 month ago
JSON representation
Script that cycles through a list of views (view IDs) and makes a snapshot of custom dimension, custom metrics, and goals that it then pushes to an Excel file.
- Host: GitHub
- URL: https://github.com/gilliganondata/ga-view-audit
- Owner: gilliganondata
- License: mit
- Created: 2017-07-06T19:09:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-09-09T09:22:25.000Z (over 1 year ago)
- Last Synced: 2025-03-15T02:54:44.418Z (about 1 month ago)
- Language: R
- Size: 239 KB
- Stars: 18
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - gilliganondata/ga-view-audit - Script that cycles through a list of views (view IDs) and makes a snapshot of custom dimension, custom metrics, and goals that it then pushes to an Excel file. (R)
README
code{white-space: pre;}
pre:not([class]) {
background-color: white;
}if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}$(document).ready(function () {
window.buildTabsets("TOC");
});Google Analytics View Auditor
This is a script intended to help the user get a handle on his/her custom dimensions, custom metrics, and goals across one or many Google Analytics views:
- Which custom dimensions, custom metrics, and goals exist, but are not recording any data, or are recording very little data?
- Are there naming inconsistencies in the values populating the custom dimensions?
While custom metrics and goals are relatively easy to eyeball within the Google Analytics web interface, if you have a lot of custom dimensions, to truly assess them, you need to build one custom report for each custom dimension.
And, for all three of these, looking at more than a handful of views can get pretty time-consuming.
This script cycles through all of the views in a user-provided list of view IDs and returns three things for each view:
- A list of all of the active custom dimensions in the view, including the top 5 values based on hits
- A list of all of the active custom metrics in the view and the total for each metric
- A list of all of the active goals in the view and the number of conversions for the goal
The output is an Excel file:
- A worksheet that lists all of the views included in the assessment
- A worksheet that lists all of the values checked – custom dimensions, custom metrics, and goals across all views
- A worksheet for each included view that lists just the custom dimensions, custom metrics, and goals for that view
How to Use
This does take a little bit of setup work.
Set Up a Google Project
This script uses googleAnalyticsR, and it hits the Google APIs pretty hard and fast, so you do not want to use the default project. Luckily, it’s pretty easy (and free) to set up a Google Project to work with googleAnalyticsR. Donal Phipps has put together a nice video on how to do that.
Put the Credentials in Your .Renviron File
If you put your client ID and client secret in a
.Renviron
file asGA_CLIENT_ID
ANDGA_CLIENT_SECRET
, then you are all set (remember to restart your R session if you do add them after you’re already working with this project).The following lines in the code will then read those values in. But, you can also just hardcode the values if you like to live on the wild side:
ga_client_id <- Sys.getenv("GA_CLIENT_ID")
ga_client_secret <- Sys.getenv("GA_CLIENT_SECRET")Create a key_views.csv File
This is the list of views that you want to assess. You can get these from the Google Analytics Query Explorer or through any other means. But, ultimately, they need to go into a file called
key_views.csv
located in theinput
folder. (There is a file there now that you can use as a template.)KEY: The headings for the file need to be
view_id
andlabel
.label
actually never appears in the output and is just there for your own reference as you are building the.csv
file.view_id,label
104######,Some Descriptor for Your Reference
119######,Some descriptor for your referenceIf you’re building it in Excel, it would look more like this before you exported it as a
.csv
:view_id
label104######
Some Descriptor for Your Reference119######
Some descriptor for your referenceCheck/Adjust the Date Range
The script, by default, will pull data for the last 30 days. But, you can adjust this code as you see fit if you want a different timeframe:
end_date <- Sys.Date() - 1
start_date <- end_date - 29Set How Many Custom Dimension Values to Return
The script, by default, returns the top 5 custom dimension values by hits. This can be set to any number (if there are fewer than that number for any specific dimension, it will simply return all of the values). Just update this line of the code:
custom_dim_top_x <- 5
Run the Script!
Open and run
ga-views-dims-metrics-goals.Rmd'. Depending on how many views and how many custom dimensions, custom metrics, and goals are set up, it may take a while to run. But, ultimately, it will export a file called
custom_data_summary.xlsxto the
output` directory.A Note on the Output File
The data_snapshot column that appears on every sheet except the first one is probably the most important piece of output. It’s three different things depending on the type of data:
- For custom dimensions, it’s the top X (default = 5) values for the custom dimension based on hits, as well as, parenthethically, the actual number of hits
- For custom metrics, it’s the total for the metric
- For goals, it’s the number of conversions for the goal
That’s about it!
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();