Skip to main content
Skip table of contents

Conversion Script

Introduction

JavaScript based conversion script which can be deployed in two ways:

  • With the marketing tag when the client wants more features than conversion measurement

  • Standalone when only conversion measurement is required

The script is designed to be deployed once for each conversion event that requires recording. This is standard practice.

Basic Structure

The script allows the client send labels and an event type for the conversion. It can pass additional values should the client wish to record attributes against and event, such as price and currency against a purchase event.

The basic structure is as follows:

CODE
<script type="text/javascript">
      window._anonevts = window._anonevts || []
      window._anonevts.push({
            labels: {conversion identifiers / labels}},
            event: {event type}}
      })
</script>

Where:

  • {conversion identifiers / labels} is a freeform label to help identify the conversion event - we will need to offer some formatting guidance based on backend/data scrience guidance.

  • {event type} identifies the type of event, such as: download, purchase, video start etc. We will also need to devise a list of accepted values for ease of computation and reporting.

Installation examples

Please see the following examples for illustrations of different scenarios; this is not intended to be a comprehensive list:

Native installation by client running the marketing tag

The Anonymised tag is already embedded and being run on every page.

Each conversion on the page will need to be detected and the conversion script called, for example:

CODE
<button id="conversionButton">Claim Offer</button>

<script type="text/javascript">
  // Select the button by its ID
  const button = document.getElementById('conversionButton');

  // Add click event listener
  button.addEventListener('click', function() {
    // Fire the Anonymised conversion event
    window._anonevts = window._anonevts || [];
    window._anonevts.push({
      labels: 'Claim offer',
      event: 'click'
    });
  });
</script>


Native installation by client not running the marketing tag

For every page that has conversion events to be recorded the following code will need to be embedded:

CODE
<script type="text/javascript">
      window._anonevts = window._anonevts || [];
      (function () {
        var elem = document.createElement('script')
        elem.src = 'https://storage.googleapis.com
          /idward-cmp-v2-dev/light/conversion.js?v=1.8.0'
        elem.type = 'text/javascript'
        elem.setAttribute('client-id', {client ID}})
        var scr = document.getElementsByTagName('script')[0]
        scr.parentNode.insertBefore(elem, scr)
      })()
</script>

Notes:

  • Where {client ID} is the client ID, such as MQ==

Each conversion on the page will need to be detected and the conversion script called, for example:

CODE
<button id="conversionButton">Claim Offer</button>

<script type="text/javascript">
  // Select the button by its ID
  const button = document.getElementById('conversionButton');

  // Add click event listener
  button.addEventListener('click', function() {
    // Fire the Anonymised conversion event
    window._anonevts = window._anonevts || [];
    window._anonevts.push({
      labels: 'Claim offer',
      event: 'click'
    });
  });
</script>

Google Tag Manager Implementations

Similarly the client will either be running the Anonymised tag or not.

Where they are running the Anonymised tag, it will already have its own GTM tag and trigger firing on every page.

In this scenario, the developer will create a new tag for every conversion event required and an appropriate trigger.

The code for the tags custom HTML will be:

CODE
<script type="text/javascript">
          window._anonevts = window._anonevts || []
          window._anonevts.push({
                labels: 'Claim Offer',
                event: 'click'
          })
</script>

Where the Anonymised tag is not installed, the following tag will need to be fired on every page:

CODE
<script type="text/javascript">
      window._anonevts = window._anonevts || [];
      (function () {
        var elem = document.createElement('script')
        elem.src = 'https://storage.googleapis.com
          /idward-cmp-v2-dev/light/conversion.js?v=1.8.0'
        elem.type = 'text/javascript'
        elem.setAttribute('client-id', {client ID}})
        var scr = document.getElementsByTagName('script')[0]
        scr.parentNode.insertBefore(elem, scr)
      })()
</script>

Notes:

  • Where {client ID} is the client ID, such as MQ==

Again the developer will create a new tag for every conversion event required and an appropriate trigger.

CODE
<script type="text/javascript">
          window._anonevts = window._anonevts || []
          window._anonevts.push({
                labels: 'Claim Offer',
                event: 'click'
          })
</script>

Guidance on the additional parameters

Should the event be a purchase, the client may wish to pass in additional fields, for example:

CODE
<script type="text/javascript">
          window._anonevts = window._anonevts || []
          window._anonevts.push({
              labels: 'PurchaseCompleted',
              event: 'purchase',
              value: '99.99',
              currency: 'USD'
          })
</script>

For more examples and information, see: https://github.com/id-ward/marketing-tag-js/blob/master/conversionTag/README.md

Other things to note

  1. When the Anonymised tag is deployed and there has been an opportunity for the tag to log in the user, the UUID will be passed to the /v3/public/beacon and captured

  2. In all cases, the conversion will record:

    1. IP address

    2. Useragent

    3. Timestamp

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.