Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / google_analytics_api_v3_10krows_nosampling_multiple_profiles_ryanpraski.py
Last active February 1, 2024 13:44
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.
#!/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 / 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"])
<script type="text/javascript">
(function(dataLayer) {
var i = 0;
var jwpVideoIsPlaying = false;
//array of percentages at which progress notifications are pushed to the dataLayer
var markers = [10, 25, 50, 75, 90]; //adjust these values if you want different progress reports
var playersMarkers = [];
function findObjectIndexById(haystack, key, needle) {
for (var i = 0; i < haystack.length; i++) {
@ryanpraski
ryanpraski / google_analytics_real-time_app_script.js
Last active March 21, 2022 11:30
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/
// 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 / 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 / pass_adobe_visitor_id_s_vi_cookie_cross_domain_in_query_parameter.js
Last active May 18, 2021 02:46
Pass the Adobe Analytics Visitor id s_vi cookie cross domain in a query parameter
@ryanpraski
ryanpraski / google_search_console_daily.R
Last active April 27, 2021 06:49
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…
## 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 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)
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 / costdata.gs
Last active January 19, 2021 17:03 — forked from chipoglesby/costdata.gs
Cost Data Upload via Google Analytic's Management API with Google Sheets
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());