Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / adobe_analytics_count_visitors_to_group_of_pages.R
Last active May 9, 2017 16:03
How many unique visitor viewed two or more of a group of pages (in this case shoes or socks pages). Used Adobe Analytics data warehouse to export Visitor_ID, Pages, and Page Views then got a count of visitor ids that viewed two or more of pages that contained shoes or socks in the page name. This count of visitor ids is the number of unique visi…
library(dplyr)
library(tidyr)
library(ggplot2)
df <- read.csv("C:/Users/praskry/Desktop/more_than_1.csv", header = TRUE)
df %>% summarize(UVs = n_distinct(Visitor_ID)) #unique visitor count
df1 <-filter(df, grepl('shoes|socks',Pages)) #filter to only include prod pages
df2 <-df1 %>% group_by(Visitor_ID) %>% filter(n()>1)
df3<-df2 %>% group_by(Visitor_ID) %>% summarize(count=n())
df3 %>% group_by(count) %>% summarize(total.count=n())
@ryanpraski
ryanpraski / googleAnalyticsR_graph_session_month_year.R
Created June 1, 2017 17:20
Graph Google Analytics session data by month and year. Create a bar graph or line graph of Google Analytics sessions using googleAnalyticsR to pull data, dplyr to group data by month and year and ggplot2 to graph data.
library(googleAnalyticsR)
library(ggplot2)
library(dplyr)
#Authorize Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Use my_accounts to find the viewId. Make sure to replace this with your viewId.
my_id <- 94579701
library(dplyr)
library(ggplot2)
library(lubridate)
library(XML)
#load apple health export.xml file
xml <- xmlParse("C:\\Users\\praskry\\Desktop\\export_sleep.xml")
#transform xml file to data frame - select the Record rows from the xml file
df <- XML:::xmlAttrsToDataFrame(xml["//Record"])
@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 / adobe_analytics_automatic_link_download_tracking
Created December 6, 2017 23:34
Adobe Analytics Automatic Link and Download Tracking Functions
@ryanpraski
ryanpraski / drift_api_R_query.R
Last active January 15, 2018 05:35
drift_api_query_with_R
library(httr)
library(rjson)
url <-'https://driftapi.com/conversations/52662097/messages'
token <-'AQ14yXgTM934cMjNEGfa6epBDU6TpCIY'
query <- GET(url, add_headers('Authorization' = paste("bearer", token)))
http_status(query)
df <-fromJSON(content(query,type='text',encoding= 'UTF-8'))
@ryanpraski
ryanpraski / google_analytics_api_app_script.js
Created August 9, 2018 18:22 — forked from dcvogi/top5pages.js
Queries the data for the top 5 pages of the website.
function main(){
// Set up the parameters and variables
var sheetName = '<name>'; // The name of the sheet (not the Spreadsheet) we want to write the data e.g Sheet1
var tableId = '<table id>'; // The id of the view to query the data from e.g ga:123456
var startDate = 'yyyy-MM-dd'; // The start date of the query with the appropriate format e.g 2018-04-01 (1 April 2018)
var endDate = 'yyyy-MM-dd'; // The end date of the query with the appropriate format e.g 2018-04-30 (30 April 2018)
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
@ryanpraski
ryanpraski / previous_pageName_session_storage
Created August 28, 2018 15:02
If you want to save the previous pageName via DTM without a Plugin (getPreviousValue), you can use Session Storage. Two Pageload Rules are needed.
[Adobe Analytics|DTM] Previous pageName
If you want to save the previous pageName via DTM without a Plugin (getPreviousValue), you can use Session Storage. Two Pageload Rules are needed.
First PLR:
- Trigger Rule at “DOM Ready”
- Rule Condition: Path “.*” (regex enabled)
- Custom Code “None-Sequential Javascript”:
if(typeof(Storage) != "undefined") {
if (typeof(s) !== "undefined") {
@ryanpraski
ryanpraski / drift_google_tag_manager_data_layer_event_listener.js
Last active September 26, 2019 16:17
drift google tag manager gtm dataLayer event listeners for chat widget including playbook interactions and meeting bookings
<script>
window.drift.on('ready',function(api){
window.drift.on('message:sent',function(event){
{
dataLayer.push({
'event': 'driftInteraction',
'eventCategory': 'drift',
'eventAction': 'message sent',
'eventLabel': 'drift>message sent conversation id: ' + event.conversationId
});
@ryanpraski
ryanpraski / adobe_launch_ajax_listener_trigger().js
Last active October 9, 2019 19:42
thanks to @StewartSchilling for helping me get this figured out
_satellite.logger.log("CHECKING JQUERY", $, jQuery);
$(document).ready(function() {
_satellite.logger.log("INSTALLING HANDLER");
$(document).ajaxSuccess(function(event, xhr, settings) {
_satellite.logger.log("FIRING HANDLER", event, xhr, settings);
var alreadyRun = false;
console.log("already run false");
if ((settings.url.indexOf("/loadResults.jsp") > -1) && (alreadyRun = false)); {
_satellite.logger.log("HANDLER CAUGHT loadResults.jsp", event, xhr, settings);
alreadyRun = true;