Skip to content

Instantly share code, notes, and snippets.

View wmcraver's full-sized avatar
🌵
Learning some new things

Mitch wmcraver

🌵
Learning some new things
View GitHub Profile
@wmcraver
wmcraver / haiku.R
Last active August 20, 2016 22:11 — forked from friggeri/haiku
random heroku-like name generator in R
haiku = function () {
adjs = c(
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
"fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",
@wmcraver
wmcraver / ShowYourCard.R
Last active September 1, 2016 21:34
Used to extract analytics traffic from Page Category CSV files. Files are by day and are read in, filtered for specific information and then stored in a data frame.
needed = c("lubridate", "dplyr", "data.table", "stringr")
is.installed <- function(pkg){is.element(pkg, installed.packages()[,1])}
for (p in 1:length(needed)){ifelse(!is.installed(needed[p]), install.packages(needed[p], dependencies = T),print(paste(needed[p], " is already installed", sep = "")))}
library(lubridate)
library(dplyr)
library(data.table) #used for the %like% function
library(stringr)
@wmcraver
wmcraver / InstallPackages.R
Last active September 1, 2016 21:34
Checks for package installation. If the package does not exist, it installs them.
needed = c("lubridate", "dplyr", "data.table", "stringr")
is.installed = function(pkg){
is.element(pkg, installed.packages()[,1])
}
# For loop to run through each of the packages
for (p in 1:length(needed)){
ifelse(!is.installed(needed[p]), install.packages(needed[p], dependencies = T), print(paste(needed[p], " is already installed", sep = "")))
}
@wmcraver
wmcraver / CheckURLs.R
Last active September 28, 2016 22:41
library(httr)
library(stringr)
dat = read.csv("fileWithURLs.csv", stringsAsFactors = F)
---------------- for loop to get results ----------------
for (i in 1:nrow(dat)) {
a = GET(dat$Current.Forward[i])
dat$URL[i] = a$url
@wmcraver
wmcraver / WriteXLS.R
Last active November 10, 2016 23:28
Write multiple data frames to multiple sheets in one spreadsheet
library(WriteXLS)
# renderedExperience, marketingChannel, allMetrics are data frames
sheetList <-list("Rendered Experience" = renderedExperience, "Marketing Channel" = marketingChannel, "Key Metrics" = allMetrics)
WriteXLS(
x = sheetList,
ExcelFileName = "RenderedExperience-MarketingChannel.xlsx",
SheetNames = names(sheetList),
urlStatusChecker = function(file,urlcol) {
library(httr)
dat = read.csv(file, stringsAsFactors = F)
for (i in 1:nrow(dat)) {
dat = dat[dat[urlcol] != "",]
dat = dat = dat[!is.na(dat[urlcol]),]
a = GET(dat[i,urlcol])
dat$URL[i] = a$url
@wmcraver
wmcraver / eVarsTesting.R
Last active November 22, 2016 18:48
Provides an way to check if eVars in Adobe Analytics are receiving data and also a way to see what the data look like.
library(RSiteCatalyst)
library(dplyr)
library(lubridate)
SCAuth(
"key",
"secret",
"company"
)
@wmcraver
wmcraver / rvesttest.r
Created January 13, 2017 00:10
Test Web Scraping
library(rvest)
url2 = read_html("http://www.verticalmeasures.com/measurement-reporting/google-analytics-101-best-practices-for-ecommerce-websites/")
newxpath = as.character('//*+[contains(concat( " ", @class, " " ), concat( " ", "sidebar-widget", " " ))]//*[contains(concat( " ", @class, " " ), concat( " ", "sidebar-widget", " " ))]//ul')
titles = html_nodes(url2, css = "p")
titles = html_text(titles)
titles
@wmcraver
wmcraver / hourlyRevByDOW.r
Last active January 16, 2017 22:54
Use rSiteCatalyst to get the average revenue by day of week and hour of day for the last 30 days.
library(RSiteCatalyst)
library(lubridate)
library(dplyr)
# SCAuth Info -------------------------------------------------------------
SCAuth(key = "", #fill in with your own info
secret = "", #fill in with your own info
company = "" #fill in with your own info
@wmcraver
wmcraver / CapSectionName.js
Created January 17, 2017 00:33
Javascript extension for Tealium to capitalize the first letter of a section name so that they are consistent in the system.
sectionName = "word word word"; // The data layer value goes here. Should look like: best western rewards.
sectionNameSplit = sectionName.split(" "); // Split the sectionName into an array -- separator is a space.
for (i = 0; i < sectionNameSplit.length; i++) {
sectionNameSplit[i] = sectionNameSplit[i].substring(0,1).toUpperCase() + sectionNameSplit[i].substring(1,sectionNameSplit[i].length);
}
sectionName = sectionNameSplit.join(" "); // "Word Word Word" stored back in sectionName
// Change sectionName to value being sent to Analytics system from Tealium.