Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / googleCloudSql_query_sheets_appscript.js
Created November 4, 2017 17:02
Google Cloud SQL Query in Sheets App Script
function connectToCloudSQL() {
var params = {
ip: "INSERT IP",
user: "INSERT USER",
password: "INSERT PASSWORD",
database: "INSERT DATABASE"
}
var dbUrl = 'jdbc:mysql://' + params.ip + '/' + params.database;
@ryanpraski
ryanpraski / googleAnalyticsReporting.gs
Created July 30, 2017 01:37 — forked from chipoglesby/googleAnalyticsReporting.gs
Send your Google Analytics metrics and dimensions to Google Big Query using Google Apps Script.
//Replace xxx with your values as necessary.
function googleAnalyticsReporting() {
projectId = "xxx";
datasetId = "xxx";
tableId = 'xxx';
data = [];
yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = Utilities.formatDate(yesterday, 'UTC', "yyyy-MM-dd");
library(dplyr)
library(ggplot2)
library(lubridate)
library(XML)
#load apple health export.xml file
xml <- xmlParse("C:\\Users\\praskry\\Desktop\\export_sleep.xml")
#transform xml file to data frame - select the Record rows from the xml file
df <- XML:::xmlAttrsToDataFrame(xml["//Record"])
@ryanpraski
ryanpraski / googleAnalyticsR_graph_session_month_year.R
Created June 1, 2017 17:20
Graph Google Analytics session data by month and year. Create a bar graph or line graph of Google Analytics sessions using googleAnalyticsR to pull data, dplyr to group data by month and year and ggplot2 to graph data.
library(googleAnalyticsR)
library(ggplot2)
library(dplyr)
#Authorize Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Use my_accounts to find the viewId. Make sure to replace this with your viewId.
my_id <- 94579701
@ryanpraski
ryanpraski / adobe_analytics_count_visitors_to_group_of_pages.R
Last active May 9, 2017 16:03
How many unique visitor viewed two or more of a group of pages (in this case shoes or socks pages). Used Adobe Analytics data warehouse to export Visitor_ID, Pages, and Page Views then got a count of visitor ids that viewed two or more of pages that contained shoes or socks in the page name. This count of visitor ids is the number of unique visi…
library(dplyr)
library(tidyr)
library(ggplot2)
df <- read.csv("C:/Users/praskry/Desktop/more_than_1.csv", header = TRUE)
df %>% summarize(UVs = n_distinct(Visitor_ID)) #unique visitor count
df1 <-filter(df, grepl('shoes|socks',Pages)) #filter to only include prod pages
df2 <-df1 %>% group_by(Visitor_ID) %>% filter(n()>1)
df3<-df2 %>% group_by(Visitor_ID) %>% summarize(count=n())
df3 %>% group_by(count) %>% summarize(total.count=n())
@ryanpraski
ryanpraski / heatmap_page_scroll_depth_Google_Analytics_R.R
Last active April 6, 2017 20:56
R Script to create a heatmap the visualizes Google Analytics page scroll depth tracking. Tutorial here: http://www.ryanpraski.com/r-heatmap-tutorial-for-google-analytics/
library(googleAnalyticsR)
library(ggplot2)
#Authorized Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Use google_analytics_account_list() to find the viewId. Make sure to replace this with your viewId.
my_id <- 94579701
@ryanpraski
ryanpraski / heatmap_sessions_by_hour_by_day_of_week_google_analytics_R.R
Last active April 6, 2017 21:20
R Script to create a heatmap the visualizes Google Analytics sessions by day of week and hour of the day. Tutorial: http://www.ryanpraski.com/r-heatmap-tutorial-for-google-analytics/
library(googleAnalyticsR)
library(ggplot2)
#Authorized Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Make sure to replace this with your viewId. You can use google_analytics_account_list() to find your viewId.
my_id <- 94579701
library(googleAnalyticsR)
library(ggplot2)
#Authorize Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Use the Google Analytics Management API to see a list of Google Analytics accounts you have access to
my_accounts <- google_analytics_account_list()
View(my_accounts)
@ryanpraski
ryanpraski / pageScrollDepthv4.R
Last active December 22, 2016 22:26
Google Analytics Reporting API v4 pivot table functionality example for googleAnalyticsR. This code is for Google Analtyics page scroll depth reporting. See the blog post here: http://www.ryanpraski.com/scroll-depth-tracking-analysis-with-google-analytics-r/
## filter pivot results
pivot_dim_filter1 <- dim_filter("eventLabel",
"REGEXP",
"%|#disqus")
pivot_dim_clause <- filter_clause_ga4(list(pivot_dim_filter1))
pivme <- pivot_ga4("eventLabel",
metrics = c("totalEvents"),
maxGroupCount = 5,
@ryanpraski
ryanpraski / pageScrollDepth.R
Last active March 18, 2021 06:54
Google Analytics scroll depth tracking report using the googleAnalyticsR & tidyr package. Check out this blog post tutorial on how to use this script: http://www.ryanpraski.com/scroll-depth-tracking-analysis-with-google-analytics-r/
library(googleAnalyticsR)
library(tidyr)
#Authorized Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Use the Google Analytics Management API to see a list of Google Analytics accounts you have access to
my_accounts <- google_analytics_account_list()
View(my_accounts)