Skip to content

Instantly share code, notes, and snippets.

View randyzwitch's full-sized avatar

Randy Zwitch randyzwitch

View GitHub Profile
@randyzwitch
randyzwitch / saverealtime.R
Created March 10, 2014 14:47
RSiteCatalyst SaveRealTimeConfiguration
SaveRealTimeConfiguration("<report suite>",
metric1 = "instances",
elements1 = c("page", "referringdomain", "sitesection"),
metric2 = "revenue",
elements2 = c("referringdomain", "sitesection")
metric3 = "orders",
elements3 = c("products")
)
@randyzwitch
randyzwitch / realtime-overtime.R
Created March 10, 2014 15:04
RSiteCatalyst GetRealTimeReport - Minimal example
GetRealTimeReport("<report suite>", "instances")
@randyzwitch
randyzwitch / realtime-offset.R
Last active August 29, 2015 13:57
RSiteCatalyst GetRealTimeReport - Offsets
GetRealTimeReport("<report suite>",
"instances",
periodMinutes = "5",
periodCount = "12",
periodOffset = "10")
@randyzwitch
randyzwitch / realtime-element.R
Created March 10, 2014 15:15
RSiteCatalyst GetRealTimeReport - Element
GetRealTimeReport("mlcpwmproduction",
"instances",
"page",
periodMinutes = "9",
periodCount = "3")
@randyzwitch
randyzwitch / r-json-paste.R
Last active August 29, 2015 14:01
JSON in R using paste
#"metrics" would be a user input into a function arguments
metrics <- c("a", "b", "c")
#Loop over the metrics list, appending proper curly braces
metrics_conv <- lapply(metrics, function(x) paste('{"id":', '"', x, '"', '}', sep=""))
#Collapse the list into a proper comma separated string
metrics_final <- paste(metrics_conv, collapse=", ")
@randyzwitch
randyzwitch / python-string-interpolation.py
Created May 13, 2014 16:11
Simple Python string interpolation
In [1]: print "Here's a string subtitution for my name: %s" %("Randy")
Out[1]: "Here's a string subtitution for my name: Randy"
@randyzwitch
randyzwitch / r-json-sprintf.R
Created May 13, 2014 16:20
R JSON sprintf example
elements_list = sprintf('{"id":"%s",
"top": "%s",
"startingWith":"%s",
"search":{"type":"%s", "keywords":[%s]}
}', element, top, startingWith, searchType, searchKW2)
@randyzwitch
randyzwitch / r-toJSON-inefficient.R
Created May 13, 2014 16:45
Inefficient way to build JSON in R
#Converts report_suites to JSON
if(length(report_suites)>1){
report_suites <- toJSON(report_suites)
} else {
report_suites <- toJSON(list(report_suites))
}
#API request
json <- postRequest("ReportSuite.GetTrafficVars",paste('{"rsid_list":', report_suites , '}'))
@randyzwitch
randyzwitch / r-toJSON-efficient.R
Created May 13, 2014 16:56
using toJSON effectively
#Efficient method
library(rjson)
report_suites <- list(rsid_list=c("A", "B", "C"))
request.body <- toJSON(report_suites)
#API request
json <- postRequest("ReportSuite.GetTrafficVars", request.body)
@randyzwitch
randyzwitch / generic-adobe-analytics-api-call.json
Created May 13, 2014 17:22
Skeleton of Adobe Analytics API call v1.4
{
"reportDescription":{
"reportSuiteID":"(string)",
"date":"(string)",
"dateFrom":"(string)",
"dateTo":"(string)",
"dateGranularity":"(string)",
"metrics":[
{
"id":"(string)"