Skip to content

Instantly share code, notes, and snippets.

@ckung
Last active July 8, 2019 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckung/ef5cad5ed16f3c2391b1c2ef5b110f9e to your computer and use it in GitHub Desktop.
Save ckung/ef5cad5ed16f3c2391b1c2ef5b110f9e to your computer and use it in GitHub Desktop.
SC tracking pixels
<!-- MPARTICLE -->
<script>
//Sanity checks
window.mParticle = window.mParticle || {};
window.mParticle.eCommerce = { Cart: {} };
window.mParticle.Identity = {};
window.mParticle.config = window.mParticle.config || {};
window.mParticle.config.rq = [];
//if in nonprod
window.mParticle = {
config: {
isDevelopmentMode: true // remove this flag in production
}
};
//identify if user is logged in
window.mParticle.config.identityCallback = function (result) {
if (result.httpCode === 200 || result.httpCode === -3) {
// Publish identity success event
// Used by subscribers that depend on the mParticle identity existing (e.g. UTM tracking)
var eventName = 'mParticle:identity-success';
if (typeof Event === 'function') {
document.dispatchEvent(new Event(eventName));
}
// Keep old behavior in place
if (typeof window.SC !== 'undefined' && SC.utils && SC.utils.pubsub) {
SC.utils.pubsub.publish(eventName);
}
}
}
window.mParticle.ready = function (f) {
window.mParticle.config.rq.push(f);
};
//mparticle snippet
(function (apiKey) {
function a(o,t){return function(){t&&(o=t+"."+o);var e=Array.prototype.slice.call(arguments);e.unshift(o),window.mParticle.config.rq.push(e)}}var x=["endSession","logError","logEvent","logForm","logLink","logPageView","setSessionAttribute","setAppName","setAppVersion","setOptOut","setPosition","startNewSession","startTrackingLocation","stopTrackingLocation"],y=["setCurrencyCode","logCheckout"],z=["login","logout","modify"];x.forEach(function(o){window.mParticle[o]=a(o)}),y.forEach(function(o){window.mParticle.eCommerce[o]=a(o,"eCommerce")}),z.forEach(function(o){window.mParticle.Identity[o]=a(o,"Identity")});
var mp = document.createElement('script');
mp.type = 'text/javascript';
mp.async = true;
mp.src = ('https:' == document.location.protocol ? 'https://jssdkcdns' : 'http://jssdkcdn') + '.mparticle.com/js/v2/' + apiKey + '/mparticle.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mp, s);
})(MPARTICLE_KEY);
//Log a page view with specific attributes on every page load
window.mParticle.ready(function () {
var attrs = {
'request_referrer': document.referrer,
'request_host': window.location.host,
'request_pathname': window.location.pathname,
'request_search': window.location.search
};
mParticle.logEvent('page view', mParticle.EventType.Navigation, attrs);
});
</script>
<!-- BRANCH -->
<script>
(function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent".split(" "), 0);
branch.init(BRANCH_KEY);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment