Conversion tags and tracking purchases

After becoming familiar with conversion tracking set up, use this page to learn more about the technical aspects of conversion tracking.

There are two conversion “tag” options that we generate using a few lines of Javascript. You will have the option to create a Universal Website Tag or a Single Event Website tag. The Universal Website Tag is meant to be placed in a website universal header code so that it can track across all the pages of a website. A Single Event Tag is meant to be placed somewhere in the body code of the website so that it only tracks one page. The different implementations of these two tags leads to two different code formats and as a result, two different ways to track purchases.

The code for these tags should always be copied directly from Twitter Ads and can be modified from there. You can find your tag codes, with unique tag IDs by going to ads.twitter.com, navigating to Tools -> Conversion Tracking, and selecting View Code next to the desired conversion. Below are example tags that illustrate where to input purchase values when compared to the supplied tag code from Twitter Ads.

Universal website tag

There are 3 variables that can be added to the Universal Website Tag: value, currency, and num_items. Value and num_items can either be set up as static values, as seen in the example below, or as dynamic variables that will require working directly with a website developer. Currency is always a static value and should be set to the same currency used in your Twitter Ads account.

Code snippet
          <!-- 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='//static.ads-twitter.com/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','TAG_ID');
twq('track','Purchase', {
    //required parameters
    value: '29.95',
    currency: 'USD',
    num_items: '3',
});


</script>
<!-- End Twitter universal website tag code -->

      

Single event tag

The code for the Single Event Tag already contains all available variables with the values set to 0. The two available variables are tw_sale_amount and tw_order_quantity. Like the Universal Website tag each variable can be used as a static or dynamic variable. In the case of a Single Event Tag, each of the two variables is present three times throughout the tag; each of these 3 instances must be set to the same value or dynamic variable for the tag to properly collect a sale amount or order quantity.

Code snippet
          <!-- Twitter single-event website tag code -->
<script src="//platform.twitter.com/oct.js" type="text/javascript"></script>
<script type="text/javascript">twttr.conversion.trackPid('TAG_ID', { tw_sale_amount: 0, tw_order_quantity: 0 });</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://analytics.twitter.com/i/adsct?txn_id=TAG_ID&p_id=Twitter&tw_sale_amount=0&tw_order_quantity=0" />
<img height="1" width="1" style="display:none;" alt="" src="//t.co/i/adsct?txn_id=TAG_ID&p_id=Twitter&tw_sale_amount=0&tw_order_quantity=0" />
</noscript>
<!-- End Twitter single-event website tag code -->

      

Third-party tracking tools

We support the following third-party container tags:

  • Floodlight tags (e.x., Google Tag Manager, DoubleClick for Advertisers)
  • Universal action tags (e.x., Atlas)
  • Server-direct (“tagless”) integration with Signal

If you would like to learn the amount or quantity of the transactions taking place on your site and are using third-party tracking, you will use this code to tag your pages:

Code snippet
          <img height="1" width="1" style="display:none;" alt=" " src="https://analytics.twitter.com/i/adsct?
txn_id=l4vsO&p_id=Twitter&tw_sale_amount=AMOUNT_HERE&tw_order_quantity=QUANTITY_HERE" / >
      

Setting “AMOUNT_HERE” and “QUANTITY_HERE” values

For your transaction value and order quantity code to work properly, you have to customize your tag. The customization can be a “hardcoded transaction” that always reports the same result when an action takes place, or a “dynamic transaction” that records richer figures.

  • Hardcoded conversions are helpful if you’d like to record the same value each time. For example, if you’ve decided that someone signing up to your email list yields a value of $15 to your company, a hardcoded conversion could be placed on your “Thank you for signing-up!” page to record $15 for every sign-up.
  • Dynamic transactions should be used when you don’t want a pre-determined value assigned to each conversion. For example, if you define a conversion as a purchase and an individual’s total is $53.72, a dynamic transaction would report that amount in your Twitter Ads account. To enable this feature, you’ll need a developer to create the code or parameter that you’ll place in the “AMOUNT_HERE” or “QUANTITY_HERE” sections of the conversion tag’s code.

How to verify website tags 

Your tag begins sending data to ads.twitter.com the first time someone visits your tagged web page. Your tag doesn’t need to be activated to collect data, but if you are experiencing problems with your tag or you just want to be thorough — use these steps to explore the code for your site and verify that your website tag is placed and working properly.

Using Google Chrome

  1. Visit a page which includes a conversion tag.

  2. In your Chrome toolbar click View > Developer > Developer Tools.

  3. Click on the “Network” tab.

  4. Type “Twitter” in the filter search box and refresh the page.

  5. Check that there are two pixels installed. One should have “t.co” as the path (this is for mobile); the other should say “analytics.twitter.com” (this tracks desktop conversions).

  6. Check that the “Status” column says “200.”

  7. If you are using container tags, they will also be displayed here.

  8. In another window, navigate to your “Conversion tracking” page under “Tools” on ads.twitter.com.

    Code snippet
              <script src="//platform.twitter.com/oct.js" type="text/javascript">
    </script>
    <script type="text/javascript">twttr.conversion.trackPid('[Insert Tag ID Here]', {tw_sale_amount: 0, tw_order_quantity: 0 });</script>
    <noscript>
    <img height="1" width="1" style="display:none;" alt=" " src="https://analytics.twitter.com/i/adsct?txn_id=[Insert Tag ID Here]&p_id=Twitter$tw_sale_amount=0&tw_order_quantity=0" />
    <img height="1" width="1" style="display:none;" alt=" " src="//t.co/i/adsct?txn_id=[Insert Tag ID Here]&p_id=Twitter$tw_sale_amount=0&tw_order_quantity=0" />
    </noscript>
          
  9. Click “edit” to see your conversion tag and leave this page open for reference.

  10. Go back to your tracked page, right click and choose “Inspect Element.”

  11. Hit Command + “F” to bring up a search bar and type “twitter.”

  12. By scrolling through your code’s mentions of “twitter” you should be able to find the snippet of code that matches your tag.

  13. If you do not see your tag in the code, try reinstalling your website tag.

Using Mozilla Firefox

  1. Visit a page which includes a conversion tag.

  2. In your Firefox toolbar click Tools > Web Developer > Network.

  3. Scroll down and check for “t.co” (this tracks mobile conversions) and “analytics.twitter.com” (this tracks desktop) in the “Domain” column.

  4. Check that the “Status” column says “200.”

  5. If you are using container tags, they will also be displayed here.

  6. In another window, navigate to your “Conversion tracking” page under “Tools” on ads.twitter.com.

    Code snippet
              <script src="//platform.twitter.com/oct.js" type="text/javascript">
    </script>
    <script type="text/javascript">twttr.conversion.trackPid('[Insert Tag ID Here]', {tw_sale_amount: 0, tw_order_quantity: 0 });</script>
    <noscript>
    <img height="1" width="1" style="display:none;" alt=" " src="https://analytics.twitter.com/i/adsct?txn_id=[Insert Tag ID Here]&p_id=Twitter$tw_sale_amount=0&tw_order_quantity=0" />
    <img height="1" width="1" style="display:none;" alt=" " src="//t.co/i/adsct?txn_id=[Insert Tag ID Here]&p_id=Twitter$tw_sale_amount=0&tw_order_quantity=0" />
    </noscript>
          
  7. Click “edit” to see your conversion tag and leave this page open for reference.

  8. Go back to your tracked page, right click and choose “Inspect Element.”

  9. Hit Command + “F” to bring up a search bar and type “twitter.”

  10. By scrolling through your code’s mentions of “twitter” you should be able to find the snippet of code that matches your tag.

  11. If you do not see you tag in the code, try reinstalling your website tag.

Ready to advertise on Twitter?