Skip to content

Instantly share code, notes, and snippets.

@msure
msure / the_times_they_are_a_changin
Last active August 29, 2015 14:11
Console.log changes to Google Tag Manager's dataLayer (works in Chrome)
/*
*
* Pop this puppy into your Chrome console on a page where you need to observe changes to the dataLayer
* http://updates.html5rocks.com/2012/11/Respond-to-change-with-Object-observe
*
*/
function chaChaChaChaChanges(changes) {
n = dataLayer.length-1;
console.dir(dataLayer[n]);
@msure
msure / yum_cookies.js
Last active December 4, 2015 17:27
Examine cookie names/values for a website
function getCookies(cooksName) {
var cooks = document.cookie.split(';')
var cooksInTheKitchen = {}
cooks.forEach(function(i) {
var name = unescape(i.match(/^\s*([^=]+)/m)[1])
var value = unescape(i.match(/=(.*$)/m)[1])
if (cooksInTheKitchen[name] !== undefined) {
console.log("Trying to retrieve cookie named(" + name + "). There appears to be another property with this name though.");
}
cooksInTheKitchen[name] = value
@msure
msure / gist:385c023e7a8050a97044
Last active August 29, 2015 14:22
Accessing Google Analytic's Real-Time API
from apiclient import errors
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow
import httplib2
import json
# easy access to account/view/property when using multiple accounts (e.g., ios app, android app, website)
with open('/Users/adrianp/py/json/ga_cred.json') as p:
gc = json.load(p)
p.close()
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
# what is the database equivalent of 'hello world' anyways?
test_query = """
SELECT COUNT(*)
FROM core.users a
WHERE a.date BETWEEN '2015-01-01' AND '2015-05-31'
GROUP BY 1
@msure
msure / test_jquery.js
Created August 19, 2015 21:37
Test to confirm Google Tag Manager no longer has access to JQuery
<script>
console.log("outside test function");
+function ($) {
console.log("inside test function");
if (typeof $ == 'undefined') {
console.log("no jquery!");
} else {
console.log("test function made it past check!");
}
}(window.jQuery);
@msure
msure / testing_mysql_queries.py
Created October 16, 2015 21:08
Alternative MySQL Querying
import json
import mysql.connector
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
# p as path, c as connection
with open('/Users/path/to/database/keys/prod_db.json') as p:
c = json.load(p)
p.close()
@msure
msure / optimizely_info.js
Last active May 2, 2018 21:57
Get Information About Active Optimizely Experiments
// all of this is made possible by the optimizely javascript api, specifically:
// http://developers.optimizely.com/javascript/reference/#the-data-object
function getExperiments() {
var experimentInfo = {};
var wasRedirected = false;
/*
* create an array of experiments that are active on the page
* you must pass two tests to be placed in an active experiment:
* 1) url targeting: https://help.optimizely.com/hc/en-us/articles/200040835-URL-Targeting-Choose-where-your-experiment-runs
@msure
msure / marketo_submit_values.js
Created July 22, 2016 19:27
Example of How To Grab Marketo Form Values On Submission
MktoForms2.loadForm("//app-sjst.marketo.com", "785-UHP-775", 1057, function(form) {
// Add an onSubmit handler
form.onSubmit(function(){
// Get the form field values
var vals = form.vals();
// You may wish to call other function calls here, for example to fire google analytics tracking or the like
// callSomeFunction(vals);
// We'll just alert them to show the principle
alert("Submitted values: " + JSON.stringify(vals));
});
@msure
msure / form_values_to_datalayer.html
Created July 22, 2016 19:28
Example of How To Push Marketo Form Values to DataLayer
<script>
MktoForms2.whenReady(function (form) {
form.onSubmit(function(){
var vals = form.vals();
dataLayer.push({
'event': 'marketoFormSubmit',
'marketoCompany': vals['Company'],
'marketoLeadSource': vals['LeadSource'],
'marketoOriginalSource': vals['Original_Source_Detail__c'],
'marketoCurrentSource': vals['Source_Detail__c']
@msure
msure / values_to_datalayer_step_by_step.html
Last active July 22, 2016 20:08
Detailed Walk-Through of Marketo Form Values To DayaLayer
<script>
// all the marketo from 2.0 javascript has successfully loaded, so we can continue
MktoForms2.whenReady(function (form) {
// the user has just submitted the form
form.onSubmit(function(){
// marketo provides a form object with a nifty method to get the values from the form
// we'll store those values in a "vals" variable
var vals = form.vals();
// now we can push to the dataLayer
dataLayer.push({