Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / adobe_analytics_api_save.segment_method.txt
Last active December 2, 2015 22:49
Adobe Analytics API Create Segment Example- Method Segments.Save
{
"definition":{
"container":{
"type":"hits",
"operator":"equals",
"rules":[
{
"element":"evar47",
"operator":"equals",
"value":"loggedin"
@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);
@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 / 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 / google_search_console_90_days.R
Last active April 5, 2016 16:13
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.
## 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 / 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 / nonbrand_keyword_dataviz_Rshiny_searchConsoleR.R
Last active April 12, 2016 18:06
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.
library(shiny)
library(ggvis)
runApp(shinyApp(
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("choose_dataset")
),
mainPanel(ggvisOutput("plot1"), ggvisOutput("plot2"), ggvisOutput("plot3"))
)
@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());
@ryanpraski
ryanpraski / salesforce_adwords_integration_web-to-lead_form_example.html
Last active December 16, 2020 14:00
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.
<!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>
@ryanpraski
ryanpraski / salesforce_adwords_google_analytics_integration_web-to-lead_form_example.html
Last active January 8, 2020 23:09
Sample Salesforce web-to-lead form that captures Adwords GCLID in a hidden form field & Google Analytics Visitor ID in another hidden form field. Make sure to replace xxxxx, yyyyy, zzzzz with your specific Salesforce field values. Include your Google Analytics Tracking ID. Create a User Scope custom dimension in your Google Analytics property Ad…
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');