This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paste this in browser console to dump your Google Tag Manager dataLayer object | |
var buffer="\n"; | |
for (var i in dataLayer){ | |
for (var j in dataLayer[i]){ | |
buffer += j+":"+dataLayer[i][j]+"\n"; | |
} | |
} | |
console.trace(buffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Build the package ------------- | |
## Now, build the `googletagmanagerv1.auto` package | |
# devtools::install_local("C:/Users/Manos/dev/R/autoGoogleAPI/googletagmanagerv1.auto") | |
# Package: googletagmanagerv1.auto | |
# Title: Tag Manager API | |
# Version: 0.0.0.9000 | |
# Authors@R: c(person("Mark", "Edmondson",email = "m@sunholo.com", | |
# role = c("aut", "cre"))) | |
# Description: Accesses Tag Manager accounts and containers. Auto-generated via | |
# googleAuthR. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requirements ----------------------------------- | |
require(googleAnalyticsR) | |
require(lubridate) | |
require(dataframes2xls) | |
## Authentication with GA ------------------------- | |
options(googleAuthR.scopes.selected = | |
c("https://www.googleapis.com/auth/webmasters", | |
"https://www.googleapis.com/auth/analytics", | |
"https://www.googleapis.com/auth/analytics.readonly")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SPREADSHEET_URL = ""; | |
function facebookSpend() { | |
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL); | |
var sheet = ss.getSheetByName('facebook'); | |
var values = []; | |
Utilities.sleep(1000); | |
var fullUrl = 'https://graph.facebook.com/v2.3/act_xxx/stats?access_token=xxx'; | |
var fetchRequest = UrlFetchApp.fetch(fullUrl); | |
var results = JSON.parse(fetchRequest.getContentText()); | |
Logger.log(results.spent/100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# PREDICTING LONG TERM CUSTOMER VALUE WITH BTYD PACKAGE | |
# Pareto/NBD (negative binomial distribution) modeling of | |
# repeat-buying behavior in a noncontractual setting | |
# | |
# Matthew Baggott, matt@baggott.net | |
# | |
# Accompanying slides at: | |
# http://www.slideshare.net/mattbagg/baggott-predict-customerinrpart1# | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT orders.customerid, | |
orders.transactiondate, | |
orders.transactionamount, | |
cohorts.cohortdate | |
FROM orders | |
JOIN (SELECT customerid, | |
Min(transactiondate) AS cohortDate | |
FROM orders | |
GROUP BY customerid) AS cohorts | |
ON orders.customerid = cohorts.customerid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(RMySQL) | |
require(ggplot2) | |
require(scales) | |
myusername = "peter" | |
mypassword = "sekret" | |
system('ssh -f pe@192.168.0.10 -L 3306:localhost:3306 -N -o ExitOnForwardFailure=yes') | |
con <- dbConnect(MySQL(), | |
user=myusername, password=mypassword, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT type, tagcount, ROUND(ratio*10000)/100 as percent FROM ( | |
SELECT | |
COUNT(DISTINCT(pageid)) tagcount, | |
RATIO_TO_REPORT(tagcount) OVER() AS ratio, | |
CASE | |
WHEN url CONTAINS "google-analytics.com" THEN "Google Analytics" | |
WHEN url CONTAINS "piwik" then "Piwik" | |
WHEN url CONTAINS "webtrends" then "WebTrends" | |
WHEN url CONTAINS "s_code" then "Omniture" | |
WHEN url CONTAINS "ntpagetag" THEN "Unica" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pageSpeed(url) { | |
url = url || 'http://ctrlq.org/'; | |
var APIkey = 'XYZ'; // Get the API key from Google Dev Console | |
var strategy = 'desktop'; // 'desktop' or 'mobile' | |
var api = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=' | |
+ url + '&key=' + APIkey + '&strategy=' + strategy; | |