Created
August 25, 2021 04:50
-
-
Save ShuvoHabib/a2eefbef763c57e11cca28871441d0d3 to your computer and use it in GitHub Desktop.
Customerio for React
This file contains 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
const addScript = (settings) => { | |
const script = document.createElement('script') | |
const { async, text, src, id } = settings | |
if (async) script.async = settings['async'] | |
if (text) script.text = settings['text'] | |
if (src) script.src = settings['src'] | |
if (id) script.id = settings['id'] | |
document.body.appendChild(script) | |
} | |
const site_id = process.env.GATSBY_ENV_CIO_SITE_ID | |
let cio_url = 'https://assets.customer.io/assets/track.js' | |
if (is_eu_country) { | |
cio_url = 'https://assets.customer.io/assets/track-eu.js' | |
} | |
addScript({ | |
text: ` | |
var _cio = _cio || []; | |
var a,b,c;a=function(f){return function(){_cio.push([f]. | |
concat(Array.prototype.slice.call(arguments,0)))}};b=["load","identify", | |
"sidentify","track","page"];for(c=0;c<b.length;c++){_cio[b[c]]=a(b[c])}; | |
var t = document.createElement('script'), | |
s = document.getElementsByTagName('script')[0]; | |
t.async = true; | |
t.id = 'cio-tracker'; | |
t.setAttribute('data-site-id', '${site_id}'); | |
t.src = '${cio_url}' | |
//If your account is in the EU, use: | |
s.parentNode.insertBefore(t, s);`, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment