Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / apple_health_analysis_R.r
Created July 14, 2016 21:21
Analyze and Visualize Apple Health Kit Steps Data using R
library(dplyr)
library(ggplot2)
library(lubridate)
#load steps data into data frame
dfsteps <- read.csv("C:\\Users\\praskry\\Desktop\\apple_health_data\\StepCount.csv")
str(dfsteps)
#make endDate in a date time variable POSIXct using lubridate with eastern time zone
dfsteps$endDate <-ymd_hms(dfsteps$endDate,tz="America/New_York")
@ryanpraski
ryanpraski / apple_health_load_analysis_R.r
Last active April 30, 2023 21:08
Load Apple Health Kit export.xml file in R then analyze and visualize Steps Data using R. See the full post here: http://www.ryanpraski.com/apple-health-data-how-to-export-analyze-visualize-guide/
library(dplyr)
library(ggplot2)
library(lubridate)
library(XML)
#load apple health export.xml file
xml <- xmlParse("C:\\Users\\praskry\\Desktop\\apple_health_data\\export.xml")
#transform xml file to data frame - select the Record rows from the xml file
df <- XML:::xmlAttrsToDataFrame(xml["//Record"])
{
"real_time_settings":[
{
"metric":"instances",
"elements":[
"page", "sitesection", "referringdomain"
],
"min_granularity":"1",
"name":"Content Real Time Report",
"ui_report":"true"
@ryanpraski
ryanpraski / real-time_adobe_analytics_multiple_filters.json
Created September 8, 2016 14:31
Multiple filters to an Adobe Analytics real-time API query
{
"reportDescription":{
"source": "realtime",
"reportSuiteID":"rtd-example",
"metrics":[
{"id":"pageviews"}
],
"elements": [
{
"id": "page",
@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)
@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,
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 / 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
@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 / 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())