Skip to content

Instantly share code, notes, and snippets.

View robhammond's full-sized avatar

Rob Hammond robhammond

View GitHub Profile
@robhammond
robhammond / Custom Site Groupings - Data Studio.js
Last active August 6, 2018 16:49
Custom Site Groupings dimension - Data Studio
CASE
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?(mirror.co.uk|dailyrecord.co.uk|irishmirror.ie|insider.co.uk|belfastlive|glasgowlive|dublinlive|rsvplive.ie).*$")) THEN "Nationals"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?(manchestereveningnews.co.uk|liverpoolecho.co.uk|walesonline|birminghammail|chroniclelive|bristolpost|hulldailymail|nottinghampost|plymouthherald|leicestermercury).*$")) THEN "Regional Capitals"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?(derbytelegraph|gazettelive|stokesentinel|coventrytelegraph|examiner|cambridge-news|grimsbytelegraph|chesterchronicle|leeds-live|getwestlondon|burtonmail|scunthorpetelegraph).*$")) THEN "Urban Hub"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?(croydonadvertiser|hertfordshiremercury|birminghampost|macclesfield-express|crewechronicle|rossendalefreepress|accringtonobserver|loughboroughecho|hinckleytimes).*$")) THEN "Community Sites"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?(dailypost|devonlive|gloucestershirelive|getsurrey|somerse
@robhammond
robhammond / Custom Page Type - Data Studio.js
Last active July 10, 2018 11:23
Custom Page Type Dimension - Data Studio
CASE
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?/all-about/.*?")) THEN "Topic"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),".*?-[0-9]+$")) THEN "Article"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),"^https?://[^/]+/.*?/$")) THEN "Section"
WHEN (REGEXP_MATCH(Page/Screen Path (Clean),"^https?://[^/]+/$")) THEN "Home"
ELSE "(Other)"
END
@robhammond
robhammond / Custom Country - Data Studio.js
Created July 10, 2018 08:59
Custom Country - Data Studio dimension
CASE
WHEN (country="United Kingdom") THEN "UK"
WHEN (country="United States") THEN "USA"
WHEN (country="India") THEN "India"
WHEN (country="Ireland") THEN "Ireland"
ELSE "(Other)"
END
@robhammond
robhammond / Custom Medium - Data Studio.js
Created July 10, 2018 08:38
Custom Acquisition channel - Data Studio
CASE
WHEN ((Source="direct" AND Medium="(not set)") OR Medium="(none)") THEN "Direct"
WHEN Medium="organic" THEN "Organic Search"
WHEN (Social Source Referral="Yes" OR REGEXP_MATCH(Medium,"^(social|social-network|social-media|sm|social network|social media)$")) OR REGEXP_MATCH(Source,"(facebook|t.co|reddit|fark|linkedin|pinterest)") THEN "Social"
WHEN Medium="email" THEN "Email"
WHEN Medium="referral" and not(REGEXP_MATCH(Source,"(facebook|t.co|reddit|fark|linkedin|pinterest)") ) THEN "Referral"
ELSE "(Other)"
END
@robhammond
robhammond / grab-image-info.pl
Created June 8, 2018 17:04
Grab metadata from images contained in URLs
#!/usr/bin/env perl
use Modern::Perl;
use Mojo::UserAgent;
use Mojo::JSON qw(decode_json);
use Image::Size qw(imgsize);
use POSIX;
my $urls = [...];
@robhammond
robhammond / convert-decimal-to-fraction.pl
Created June 8, 2018 17:01
Convert decimal numbers to fractions
sub float2rat {
my $x = shift;
my $tolerance = 1.0E-6;
my $h1 = 1;
my $h2 = 0;
my $k1 = 0;
my $k2 = 1;
my $b = $x;
do {
@robhammond
robhammond / evergreen-regex.pl
Created March 2, 2018 14:47
Create a regular expression to identify evergreen content in Google Analytics
#!/usr/bin/env perl
use Modern::Perl;
use DateTime;
my $past = DateTime->now->subtract(months => 6);
my $past_year = $past->year();
my $past_month = $past->month();
my $past_2_year = $past->subtract(years => 1)->format_cldr('yy');
my $y_str;
@robhammond
robhammond / extract-monthly-data.pl
Created February 20, 2018 17:29
Extract monthly data from Adobe Analytics to a Google BigQuery table. Once completed, use `cat *.json >> all.json` to combine files for import into BQ
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use DateTime;
use FindBin qw($Bin);
use Getopt::Long;
use Modern::Perl;
use Mojo::JSON qw(encode_json);
@robhammond
robhammond / redirect.pl
Last active February 16, 2018 15:43 — forked from Logioniz/redirect.pl
Redirect from http to https with mojolicious
#!/usr/bin/perl
# To run need listen two ports: 80, 443
# sudo morbo 12.pl -l https://*:443?cert%3D%2Fhome%2Flogioniz%2Fcert%2Fserver.crt%26key%3D%2Fhome%2Flogioniz%2Fcert%2Fserver.key%26verify%3D0x00 -l http://*:80
# go to url in browser http://your_ip/qwe/asd
use Mojo::Base -strict;
use Mojolicious::Lite;
@robhammond
robhammond / verify-client-ids.js
Last active December 14, 2022 06:58
Puppeteer script to check that Google Analytics Client ID is consistent across different platforms
'use strict';
const puppeteer = require('puppeteer');
// Test scenarios
// 4 different entrypoints
// ~8 different cookie setting scenarios (ie every page has at least 1 video)
// 2 different pre-set options - cookies and cookie-less
const reqUrls = [