Created
April 7, 2022 17:10
-
-
Save Thorium/b154fb2f2feccb04fcaaf244559eb5b2 to your computer and use it in GitHub Desktop.
TikTok Pixel tag valid TypeScript / JavaScript
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
function tiktokTag() { | |
try { | |
window.TiktokAnalyticsObject = 'ttq'; | |
var ttq = window.ttq = window.ttq || []; | |
ttq.methods = ["page", "track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"]; | |
ttq.setAndDefer = function(t, e) { | |
t[e] = function() { | |
t.push([e].concat(Array.prototype.slice.call(arguments, 0))) | |
} | |
}; | |
for (var i = 0; i < ttq.methods.length; i++) { ttq.setAndDefer(ttq, ttq.methods[i]); } | |
ttq.instance = function(t) { | |
for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) { ttq.setAndDefer(e, ttq.methods[n]); } | |
return e; | |
}; | |
ttq.load = function(e, n) { | |
var i = "https://analytics.tiktok.com/i18n/pixel/events.js"; | |
ttq._i = ttq._i || {}; ttq._i[e] = []; ttq._i[e]._u = i; ttq._t = ttq._t || {}; ttq._t[e] = +new Date; ttq._o = ttq._o || {}; ttq._o[e] = n || {}; | |
n = document.createElement("script"); | |
n.type = "text/javascript"; n.async = !0; n.src = i + "?sdkid=" + e + "&lib=ttq"; | |
e = document.getElementsByTagName("script")[0]; | |
e.parentNode.insertBefore(n, e) | |
}; | |
ttq.load('ABC123_MY_ID_HERE'); | |
ttq.page(); | |
} catch (e) { | |
console.log(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment