Created
May 17, 2017 07:39
-
-
Save monan/47534f1c409d0c8d13ba7fa6461236f5 to your computer and use it in GitHub Desktop.
crozer tampermonkey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name www.crozerkeystone.org | |
// @namespace https://www.crozerkeystone.org/ | |
// @version 0.1 | |
// @description Implements Acquia Lift | |
// @author Mike Monan | |
// @match *://www.crozerkeystone.org/* | |
// @grant none | |
// @xrequire https://code.jquery.com/jquery-latest.js | |
// @copyright 2017 acquia.com | |
// ==/UserScript== | |
$(document).ready(function() { | |
console.log('Tampermonan version 1.0'); | |
// Build Acquia Lift data layer | |
window.AcquiaLift = { | |
account_id: 'CROZER', | |
site_id: 'CROZERPROD', | |
liftAssetsURL: "https://lift3assets.lift.acquia.com/stable", | |
liftDecisionAPIURL: "https://us-east-1-demo-decisionapi.lift.acquia.com", | |
authEndpoint: "https://us-east-1-demo-oauth2.lift.acquia.com/authorize", | |
contentReplacementMode: "untrusted", | |
profile: { | |
content_type: '', | |
content_section: '', | |
content_keywords: '' | |
} | |
}; | |
// Get path and determine content type. | |
var path = window.location.pathname.split('/'); | |
//path.shift(); | |
// Empty path is home page. | |
if (path[0] === '') path[0] = 'home'; | |
console.log({'path' : path}); | |
// Add Search event... | |
setTimeout(function(){ | |
if (path[1] == 'site-search') { | |
if (urlParams.has('term')) { | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['capture', 'search', {'event_udf5':urlParams.get('term')}]); | |
} | |
} | |
} | |
}, 200); | |
switch (path[2]) { | |
// If first argument is 'cancer', assume we are on a cancer specialty page. | |
case 'cancer': | |
window.AcquiaLift.profile.content_type = 'Specialty'; | |
window.AcquiaLift.profile.event_udf10 = path[0] + ' - ' + path[1] + ' - ' + path[2] + ' - ' + path[3]; | |
window.AcquiaLift.profile.persona = 'cancer'; | |
break; | |
// If first argument is 'heart', assume we are on a cardiac specialty page. | |
case 'heart': | |
window.AcquiaLift.profile.event_udf10 = path[0] + ' - ' + path[1] + ' - ' + path[2] + ' - ' + path[3]; | |
window.AcquiaLift.profile.content_section = 'Specialty'; | |
window.AcquiaLift.profile.persona = 'cardiac'; | |
break; | |
case 'home': | |
window.AcquiaLift.profile.content_type = 'Home page'; | |
//window.AcquiaLift.profile.persona = 'medical'; | |
break; | |
default: | |
window.AcquiaLift.profile.content_type = 'Landing page'; | |
} | |
// Write Lift JS script to page. | |
var s = document.createElement('script'); | |
s.type = 'text/javascript'; | |
s.text = 'window.AcquiaLift = ' + JSON.stringify(window.AcquiaLift) + ';'; | |
var t = document.createElement("script"); | |
t.src = 'https://lift3assets.lift.acquia.com/stable/lift.js'; | |
$('head').append(s, t); | |
// Get url parameters. | |
var urlParams = new URLSearchParams(window.location.search); | |
console.log(urlParams); | |
// Add home hero slot | |
if (path[0] === 'home') { | |
$('body.Home').append('<div data-lift-slot="eddd9e00-3ac2-11e7-8b4b-97f0a0a8cc44" lift-data-mode="untrusted" data-lift-css="https://alh.presales.site/sites/default/files/asset_injector/lift.css?7"></div>'); | |
// setTimeout(function(){ | |
// if (typeof _tcaq != 'undefined') { | |
// _tcaq.push(['capture', 'Person', {'persona':'medical'}]); | |
// //_tcaq.push(['capture', 'event', 'persona']); | |
// //_tcaq.push(['capture', 'persona', 'medical']); | |
// console.log('Send Lift Persona'); | |
// } | |
// }, 200); | |
} | |
// Add property content slot | |
if (path[2] === 'cancer') { | |
$('#Content').prepend('<div data-lift-slot="565b7000-3ac9-11e7-a0d3-11861b2baabb" lift-data-mode="untrusted" data-lift-css="https://alh.presales.site/sites/default/files/asset_injector/lift.css?7"></div>'); | |
setTimeout(function(){ | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['capture', 'Person', {'persona':'cancer'}]); | |
console.log('Send Lift Persona'); | |
} | |
}, 200); | |
} | |
// Add property content slot | |
if (path[2] === 'heart') { | |
$('#Content').prepend('<div data-lift-slot="ea3f44c0-3ac6-11e7-8bfe-4790a3c1252f" lift-data-mode="untrusted" data-lift-css="https://alh.presales.site/sites/default/files/asset_injector/lift.css?7"></div>'); | |
setTimeout(function(){ | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['capture', 'Person', {'persona':'cancer'}]); | |
console.log('Send Lift Persona'); | |
} | |
}, 200); | |
} | |
// Add campagin click thru event. | |
if (urlParams.has('ref')) { | |
setTimeout(function(){ | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['captureIdentity', urlParams.get('ref'), 'account']); | |
console.log('Send Lift campaign click thru event'); | |
} | |
}, 200); | |
} | |
/* | |
// Add Login email event | |
$("div#userLoginPopup form#headerLoginForm button#qa-signin-md").click(function() { | |
console.log("Logging In..."); | |
var myform = $(this).parents('form:first'); | |
console.log($("input[name='j_username']",myform).val()); | |
var email = $("input[name='j_username']",myform).val(); | |
event.preventDefault(); | |
$('#qa-signin-md').attr('onclick','').unbind('click'); | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['captureIdentity', email, 'email']); //, {}, {'identity':{name:'name',account:'account'} }]); | |
setTimeout(function(){console.log('Send Lift event');}, 500); | |
} | |
}); | |
// Add to cart event | |
$("#qa-product0-addToCart").click(function() { | |
console.log("Added 0 to Cart"); | |
var myform = $(this).parents('form:first'); | |
console.log($("input[name='productNumber']",myform).val()); | |
var sku_code = $("input[name='productNumber']",myform).val(); | |
var product_name = $("input[name='productNumber']",myform).val(); | |
var unit_sale_price = "84.00"; | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['capture', 'Add to cart', {'event_udf4':sku_code,'event_udf5':product_name,'event_udf6':unit_sale_price}]); | |
setTimeout(function(){console.log('Send Lift event');}, 500); | |
} | |
}); | |
// Add to cart event | |
$("#qa-product1-addToCart").click(function() { | |
console.log("Added 1 to Cart"); | |
var myform = $(this).parents('form:first'); | |
console.log($("input[name='productNumber']",myform).val()); | |
var sku_code = $("input[name='productNumber']",myform).val(); | |
var product_name = $("input[name='productNumber']",myform).val(); | |
var unit_sale_price = "144.00"; | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['capture', 'Add to cart', {'event_udf4':sku_code,'event_udf5':product_name,'event_udf6':unit_sale_price}]); | |
setTimeout(function(){console.log('Send Lift event');}, 500); | |
} | |
}); | |
// Add to cart event | |
$("#qa-product2-addToCart").click(function() { | |
console.log("Added 2 to Cart"); | |
var myform = $(this).parents('form:first'); | |
console.log($("input[name='productNumber']",myform).val()); | |
var sku_code = $("input[name='productNumber']",myform).val(); | |
var product_name = $("input[name='productNumber']",myform).val(); | |
var unit_sale_price = "113.00"; | |
if (typeof _tcaq != 'undefined') { | |
_tcaq.push(['capture', 'Add to cart', {'event_udf4':sku_code,'event_udf5':product_name,'event_udf6':unit_sale_price}]); | |
setTimeout(function(){console.log('Send Lift event');}, 500); | |
} | |
}); | |
*/ | |
}); | |
function randomNumberFromRange(min,max) { | |
return Math.floor(Math.random()*(max-min+1)+min); | |
} | |
function wordpress_dataLayer() { | |
content_sections = []; | |
$('.main-navigation li.current-menu-parent').each(function() { | |
content_sections.push($(this).text()); | |
}); | |
window.AcquiaLift.profile.content_type = 'post'; | |
window.AcquiaLift.profile.content_section = content_sections.join(); | |
} | |
// Universal Variable (UV) is a global JavaScript object that contains all the dynamic variables that matter on any given page. | |
// UV is closely linked to Qubit's tag management system, which is used to deploy technologies. | |
function qubit_dataLayer() { | |
if (typeof universal_variable != 'undefined') { | |
if (typeof universal_variable.page != 'undefined') { | |
window.AcquiaLift.profile.content_type = universal_variable.page.type; | |
var breadcrumbs = universal_variable.page.breadcrumb; | |
// Save first breadcrumb (section) to last section viewed. | |
for (var i in breadcrumbs) { | |
window.AcquiaLift.profile.person_udf4 = universal_variable.page.breadcrumb[i]; | |
break; | |
} | |
// Save breadcrumbs array to comma delimited string. | |
window.AcquiaLift.profile.content_section = breadcrumbs.join(); | |
if (typeof universal_variable.product != 'undefined') { | |
// Save product to AcquiaLift data layer. | |
window.AcquiaLift.product = universal_variable.product; | |
// Recalculate last section and breadcrumbs if on product page. | |
window.AcquiaLift.profile.person_udf4 = universal_variable.product.category; | |
window.AcquiaLift.profile.content_section = universal_variable.product.category + ',' + universal_variable.product.subcategory; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment