Adding Conversion Tracking without <script> tags


#1

Hi,

Trying to embed our pixels in Launchrock, and to do so we need to be able to plug the code into the Javascript section of the advanced editor.

In this area, something like the GA code snippet syntax works perfectly:

// Google Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXX-X', 'auto');

We don’t know anything about JS. How can we change our conversion tracking snippet into a similar function?

<script src="//platform.twitter.com/oct.js" type="text/javascript"></script>
<script type="text/javascript">
twttr.conversion.trackPid('XXX');</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://analytics.twitter.com/i/adsct?txn_id=XXX&p_id=Twitter" />
<img height="1" width="1" style="display:none;" alt="" src="//t.co/i/adsct?txn_id=XXX&p_id=Twitter" /></noscript>

Put the code straight into a, what, jQuery or regular JS syntax, in other words? No script tags.

Sorry if I sound like a complete buffoon, lol.

Thanks!

Andy


#2

You can load a script asynchronously through jQuery’s getScript function then log the conversion.

jQuery.getScript("https://platform.twitter.com/oct.js").done(function(){
twttr.conversion.trackPid('XXX');
})

You would miss the image-based trackers included on the page when no JavaScript is available. If you have a way to add the code in between the <noscript> elements on the page you will have better coverage.


#3

Hi Niall,

Thanks for that!

Here’s what we’ve added:

// Twitter Conversion Tracking
$.getScript("https://platform.twitter.com/oct.js").done(function(){
twttr.conversion.trackPid('XXX');
});

container.append('<img height="1" width="1" style="display:none;" alt="" src="https://analytics.twitter.com/i/adsct?txn_id=XXX&p_id=Twitter" />'); // Twitter pixel

container.append('<img height="1" width="1" style="display:none;" alt="" src="//t.co/i/adsct?txn_id=XXX&p_id=Twitter" />'); // Twitter pixel

Our panel was saying we were tracking prior to adding the script, just by appending the pixels?

Is simply adding the pixels as we’ve done all that’s required?

From what you’ve said it sounds like the pixels are the fallback in a no JS environment. So what’s the advantage of the JS?

Thanks, will followup with our test results using your snippet!

Andy


#4

The img elements should be wrapped in a noscript. They are not needed when JavaScript is available on the page.


#5