Created
May 10, 2021 17:43
-
-
Save troex/cb5cf8ebf3e91fe375ca7b2dcf3cf4e0 to your computer and use it in GitHub Desktop.
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
<script type="text/javascript"> | |
!function(){var Attribution=window.Attribution=window.Attribution||[];if(!Attribution.initialize)if(Attribution.invoked)window.console&&console.error&&console.error("Attribution snippet included twice.");else{Attribution.invoked=!0,Attribution.methods=["setAnonymousId","trackSubmit","trackClick","initialize","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"],Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);return t.unshift(e),Attribution.push(t),Attribution}};for(var t=0;t<Attribution.methods.length;t++){var e=Attribution.methods[t];Attribution[e]=Attribution.factory(e)}Attribution.load=function(t,e){var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src="https://scripts.attributionapp.com/v2/attribution.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(i,r),e=e||{},e.projectId=t,Attribution._loadOptions=e},Attribution.SNIPPET_VERSION="4.1.0"; | |
Attribution.load("ATTRIBUTION_PROJECT_ID"); | |
Attribution.page(); | |
}}(); | |
</script> | |
<script type="text/javascript"> | |
!function() { | |
var callback = function(event) { | |
var engine = (window.Attribution || window.analytics); | |
var traits = {}; | |
var inputs = event.formElement.elements; | |
for (i = 0; i < inputs.length; i++) { | |
var name = inputs[i].name; | |
var value = inputs[i].value; | |
if ( // skip empty or reserved inputs | |
name.match(/^(page|ub)/) || | |
name == '' || | |
name == undefined || | |
value == '' || | |
value == undefined | |
) { | |
continue; | |
} | |
// work_email, business_email, etc... | |
if (name.match(/email/)) { | |
name = 'email'; | |
} | |
traits[name] = value; | |
} | |
if (engine) { | |
engine.identify(traits); | |
engine.track('Unbounce Form Submitted', { | |
unbounce_page: ub.page.name, | |
unbounce_variant: ub.page.variantId | |
}); | |
} else { | |
console.log('[Attribution] Snippet not found'); | |
} | |
}; | |
if (window.ub && window.ub.hooks) { | |
window.ub.hooks.beforeFormSubmit.push(callback); | |
} else { | |
console.log('[Attribution] Unounce page not detected'); | |
} | |
}(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment