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
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
/* | |
* Instructions: Place *after* the Google Analytics Snippet, | |
* so this _gaq.push executes after the _gaq.push(["_trackPageview"]); call. | |
*/ | |
_gaq.push(function() { | |
if (window.history && history.replaceState && location.search.match(/utm_/)) { | |
var query = {}; | |
location.search.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) { | |
if (! ($1).match(/^utm_/)) { | |
query[$1] = $3; |
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: visCorrel | |
# | Creates an MDS plot where the distance between variables represents | |
# | correlation between the variables (closer=more correlated) | |
# *-------------------------------------------------------------------- | |
# | Version |Date |Programmer |Details of Change | |
# | 01 |05/01/2012|Simon Raper |first version. | |
# *-------------------------------------------------------------------- | |
# | INPUTS: dataset A dataframe containing only the explanatory | |
# | variables. It should not contain missing |
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
#TV now coincides with winter. Carry over is dec, theta is dim, beta is ad_p, | |
tv_grps<-rep(0,5*52) | |
tv_grps[40:45]<-c(390,250,100,80,120,60) | |
tv_grps[92:97]<-c(390,250,100,80,120,60) | |
tv_grps[144:149]<-c(390,250,100,80,120,60) | |
tv_grps[196:201]<-c(390,250,100,80,120,60) | |
tv_grps[248:253]<-c(390,250,100,80,120,60) | |
if (adstock_form==2){adstock<-adstock_calc_2(tv_grps, dec, dim)} | |
else {adstock<-adstock_calc_1(tv_grps, dec, dim)} |
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: create_test_sets | |
# | Creates simple artifical marketing mix data for testing code and | |
# | techniques | |
# *-------------------------------------------------------------------- | |
# | Version |Date |Programmer |Details of Change | |
# | 01 |29/11/2011|Simon Raper |first version. | |
# *-------------------------------------------------------------------- | |
# | INPUTS: base_p Number of base sales | |
# | trend_p Increase in sales for every unit increase |
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
##Creating Random Sales Data of the format CustomerId (unique to each customer), Sales.Date,Purchase.Value | |
sales=data.frame(sample(1000:1999,replace=T,size=10000),abs(round(rnorm(10000,28,13)))) | |
names(sales)=c("CustomerId","Sales Value") | |
sales.dates <- as.Date("2010/1/1") + 700*sort(stats::runif(10000)) | |
#generating random dates |
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
#### Connecting to Google Analytics API via R | |
#### Uses OAuth 2.0 | |
#### https://developers.google.com/analytics/devguides/reporting/core/v3/ for documentation | |
# Install devtools package & rga - This is only done one time | |
install.packages("devtools") | |
library(devtools) | |
install_github("rga", "skardhamar") | |
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
############################################### | |
## | |
## Attempt no 2 at building a shiny web app | |
## for AB Testing use - using global.R | |
## | |
## global.R - loading and defining variables for the global environment | |
## | |
############################################### | |
# Pallette used in some charts as a general indicator color for better or worse that the control group |
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
# Use a call to the Management API to query your Profiles and select among them | |
ga$getProfiles() | |
# Define the ids and web properties to work with. The web.proporties is reserved for | |
# the name of the ids for labeling reasons etc | |
ids<-c() | |
web.properties<-c() |