Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / adobe_analytics_api_save.segment_method.txt
Last active Dec 2, 2015
Adobe Analytics API Create Segment Example- Method Segments.Save
View adobe_analytics_api_save.segment_method.txt
{
"definition":{
"container":{
"type":"hits",
"operator":"equals",
"rules":[
{
"element":"evar47",
"operator":"equals",
"value":"loggedin"
@ryanpraski
ryanpraski / google_search_console_90_days.R
Last active Apr 5, 2016
Download Google Search Console data (formerly webmaster tools) to R using searchConsoleR package. This script downloads the last 90 days of available data: from 93 days ago to 3 days ago and write the data to a .csv file.
View google_search_console_90_days.R
## A script to download and archive Google search console analytics (formerly webmaster tools)
##
## searchConsoleR package created by Mark Edmondson (http://markedmondson.me)
##
## This script downloads and writes data to .csv for the last 90 days of data available
## load the required libraries
## (Download them with install.packages("googleAuthR") and install.packages("searchConsoleR") if necessary
library(googleAuthR)
library(searchConsoleR)
@ryanpraski
ryanpraski / nonbrand_keyword_dataviz_Rshiny_searchConsoleR.R
Last active Apr 12, 2016
Shiny app to visualize clicks, impressions, and position by week for Google Organic non brand keywords. Uses searchConsoleR library to pull Google Search Console data.
View nonbrand_keyword_dataviz_Rshiny_searchConsoleR.R
library(shiny)
library(ggvis)
runApp(shinyApp(
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("choose_dataset")
),
mainPanel(ggvisOutput("plot1"), ggvisOutput("plot2"), ggvisOutput("plot3"))
)
View Adobe Analytics Real-Time Report API Settings.json
{
"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 Sep 8, 2016
Multiple filters to an Adobe Analytics real-time API query
View real-time_adobe_analytics_multiple_filters.json
{
"reportDescription":{
"source": "realtime",
"reportSuiteID":"rtd-example",
"metrics":[
{"id":"pageviews"}
],
"elements": [
{
"id": "page",
@ryanpraski
ryanpraski / apple_health_analysis_R.r
Created Jul 14, 2016
Analyze and Visualize Apple Health Kit Steps Data using R
View apple_health_analysis_R.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 / pageScrollDepthv4.R
Last active Dec 22, 2016
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/
View pageScrollDepthv4.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 / hello_analytics_api_v3_10krows_nosampling_ryanpraski_single_csv.py
Created Feb 8, 2016
Export more than 10,000 rows & a solution for the sampling limitations of Google Analytics using Python and the Google Analytics API. Includes functionality to pull data from multiple Google Analytics profiles. This version puts all data for all the profiles into a single csv file.
View hello_analytics_api_v3_10krows_nosampling_ryanpraski_single_csv.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@ryanpraski
ryanpraski / heatmap_page_scroll_depth_Google_Analytics_R.R
Last active Apr 6, 2017
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/
View heatmap_page_scroll_depth_Google_Analytics_R.R
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 Apr 6, 2017
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/
View heatmap_sessions_by_hour_by_day_of_week_google_analytics_R.R
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