Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / google_sheet_script_removeEmptyRows_removeEmptyColumns.js
Last active September 21, 2017 07:30
Google Sheet Script removeEmptyRows removeEmptyColumns
//Remove All Empty Columns in the Entire Workbook
function removeEmptyColumns() {
var ss = SpreadsheetApp.getActive();
var allsheets = ss.getSheets();
for (var s in allsheets){
var sheet=allsheets[s]
var maxColumns = sheet.getMaxColumns();
var lastColumn = sheet.getLastColumn();
if (maxColumns-lastColumn != 0){
sheet.deleteColumns(lastColumn+1, maxColumns-lastColumn);
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_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 / hello_analytics_api_v3_10krows_nosampling_ryanpraski_single_csv.py
Created February 8, 2016 20:24
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.
#!/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 / 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 / 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 / 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",