Twitter generated a conversion tracking snippet for my twitter ads account
I’ve tried following the documentations and examples on the internet and I’ve come up with the following code
var _twttr = window._twttr || (window._twttr = []);
var _loadTwitter = function() {
var interval = setInterval(function() {
if (!_twttr.loaded) {
var twitterScript = document.createElement('script');
twitterScript.async = true;
twitterScript.src = '//platform.twitter.com/oct.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(twitterScript, s);
_twttr.loaded = true;
}
else if(_twttr.loaded){
twttr.conversion.trackPid('ntsd0', { tw_sale_amount: subTotal, tw_order_quantity: totalQuantity })
clearInterval(interval);
}
}, 200);
};
_loadTwitter();
subTotal and totalQuantity are declared and calculated earlier in the code.
The problem Im having is I get the following error when I try firing twitter’s trackPid:
“Uncaught ReferenceError: twttr is not defined”
If I try opening the console on chrome and firing the pixel manually all I get as an answer is ‘undefined’
Any thoughts? Should I be doing this differently? I’m using Google Tag Manager.