Universal Website Tag is adding script elements to HTML DOM for every event

ads

#1

I noticed when I track some event with the twq api, a new script element is appended to my webapp’s html body.

twq('track', 'Test')
<script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&amp;p_user_id=0&amp;txn_id=nxlka&amp;events=%5B%5B%22pageview%22%2Cnull%5D%5D&amp;tw_sale_amount=0&amp;tw_order_quantity=0&amp;tw_iframe_status=0&amp;tpx_cb=twttr.conversion.loadPixels" type="text/javascript"></script><script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&amp;p_user_id=0&amp;txn_id=nxlka&amp;events=%5B%5B%22test%22%2Cnull%5D%5D&amp;tw_sale_amount=0&amp;tw_order_quantity=0&amp;tw_iframe_status=0&amp;tpx_cb=twttr.conversion.loadPixels" type="text/javascript"></script><script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&amp;p_user_id=0&amp;txn_id=nxlka&amp;events=%5B%5B%22test%22%2Cnull%5D%5D&amp;tw_sale_amount=0&amp;tw_order_quantity=0&amp;tw_iframe_status=0&amp;tpx_cb=twttr.conversion.loadPixels" type="text/javascript"></script><script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&amp;p_user_id=0&amp;txn_id=nxlka&amp;events=%5B%5B%22test%22%2Cnull%5D%5D&amp;tw_sale_amount=0&amp;tw_order_quantity=0&amp;tw_iframe_status=0&amp;tpx_cb=twttr.conversion.loadPixels" type="text/javascript"></script><script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&amp;p_user_id=0&amp;txn_id=nxlka&amp;events=%5B%5B%22test%22%2Cnull%5D%5D&amp;tw_sale_amount=0&amp;tw_order_quantity=0&amp;tw_iframe_status=0&amp;tpx_cb=twttr.conversion.loadPixels" type="text/javascript"></script><script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&amp;p_user_id=0&amp;txn_id=nxlka&amp;events=%5B%5B%22test%22%2Cnull%5D%5D&amp;tw_sale_amount=0&amp;tw_order_quantity=0&amp;tw_iframe_status=0&amp;tpx_cb=twttr.conversion.loadPixels" type="text/javascript">

And then the Twitter Pixel Helper starts to report errors too:

Website tag with ID nxlka activated more than once. Website tags activating multiple times on your page can cause errors in tracking.
Website tag with ID nxlka activated more than once. Website tags activating multiple times on your page can cause errors in tracking.
Website tag with ID nxlka activated more than once. Website tags activating multiple times on your page can cause errors in tracking.
Website tag with ID nxlka activated more than once. Website tags activating multiple times on your page can cause errors in tracking.

Anyone has ran into same issue or knows how to work around it?


#2

Hi @lingvist_dev,

The appended script is expected behavior. The UWT tag isn’t complete without this script fully intact. Here is an example of the UWT tag in it’s entirety.

<!-- Twitter universal website tag code -->
<script>
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
},s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='//tellapart-test.s3.amazonaws.com/brent_uwt.js',
a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
// Insert Twitter Pixel ID and Standard Event data below
twq('init','nxlka');
twq('track','PageView');
</script>
<!-- End Twitter universal website tag code -->

Regarding the Twitter Pixel Helper errors, that happens when the same Universal Website Tag ID is called repeatedly on a given page. If the code above is only executed once, then you would not see this error.