Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / apple_health_load_analysis_R.r
Last active Jun 21, 2021
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/
View apple_health_load_analysis_R.r
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"])
@ryanpraski
ryanpraski / googleCloudSql_query_sheets_appscript.js
Created Nov 4, 2017
Google Cloud SQL Query in Sheets App Script
View googleCloudSql_query_sheets_appscript.js
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 / pass_adobe_visitor_id_s_vi_cookie_cross_domain_in_query_parameter.js
Last active May 18, 2021
Pass the Adobe Analytics Visitor id s_vi cookie cross domain in a query parameter
View pass_adobe_visitor_id_s_vi_cookie_cross_domain_in_query_parameter.js
@ryanpraski
ryanpraski / google_analytics_real-time_app_script.js
Last active May 18, 2021
Google Analytics Real-Time App Script Query- data is written to a Google Sheet then used in a Google Data Studio Dashboard by using the data studio data connector. See the full tutorial here: http://www.ryanpraski.com/google-analytics-real-time-data-studio-dashboard/
View google_analytics_real-time_app_script.js
// get time stamp of query run
function setTimeStamp(sheetName) {
SpreadsheetApp.getActive().getSheetByName(sheetName)
.getRange('C2').setValue(new Date())
}
// gaGet data
function gaGet(tableId, metrics, options) {
// Apply standard options
options = options || {};
@ryanpraski
ryanpraski / google_search_console_daily.R
Last active Apr 27, 2021
Download Google Search Console data (formerly webmaster tools) to R using searchConsoleR package. This script downloads data for the most recent day of search console data which is 3 days ago. Tutorial describing how to automate daily Google Search Console pulls using this script: http://www.ryanpraski.com/google-search-console-api-r-guide-to-ge…
View google_search_console_daily.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 most recent day of search console data (3 days ago)
## load the required libraries
## (Download them with install.packages("googleAuthR") and install.packages("searchConsoleR") if necessary
library(googleAuthR)
library(searchConsoleR)
@ryanpraski
ryanpraski / pageScrollDepth.R
Last active Mar 18, 2021
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/
View pageScrollDepth.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)
View googleAnalyticsR_tutorial.R
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 / google_analytics_api_v3_10krows_nosampling_multiple_profiles_ryanpraski.py
Last active Jan 25, 2021
A solution for exporting more than 10,000 rows and 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.
View google_analytics_api_v3_10krows_nosampling_multiple_profiles_ryanpraski.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 / costdata.gs
Last active Jan 19, 2021 — forked from chipoglesby/costdata.gs
Cost Data Upload via Google Analytic's Management API with Google Sheets
View costdata.gs
function uploadData() {
var accountId = "xxxxxxxx";
var webPropertyId = "UA-xxxxxxxx-x";
var customDataSourceId = "xxxxxxxx";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var maxRows = ss.getLastRow();
var maxColumns = ss.getLastColumn();
var data = [];
for (var i = 1; i <= maxRows; i++) {
data.push(ss.getRange([i], 1, 1, maxColumns).getValues());
@ryanpraski
ryanpraski / salesforce_adwords_integration_web-to-lead_form_example.html
Last active Dec 16, 2020
Sample Salesforce web-to-lead form that captures Adwords GCLID in a hidden form field. Make sure to replace xxxxx and yyyyy with your specific Salesforce field values.
View salesforce_adwords_integration_web-to-lead_form_example.html
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
</head>
<body>
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<script>