Javascript tracking of conversions

Avatar

By Zeno

updated less than a minute ago

Global Javascript Snippet

Before tracking any Javascript events, you need to include our global snippet.

This can be found in Settings > Tracking Codes in the navigation.

It can be placed anywhere on your page and should only be included once per page.

Tracking Conversion Events

Firstly, note that our global snippet provided in the offer source and offer sections already includes a conversion event code in it.

If your page is a thank you page where you don't care about tracking a view, just a conversion, you can use this snippet to do so.



This code contains optional placeholders for revenue, hit ID and transaction ID, which the offer source may inject.

Note: in the snippet you retrieve, depending on the offer source there will be values in CAPS should be replaced with real values, else omitted entirely if not known, e.g. HIT_ID and so on.

Javascript Event Code

A basic conversion event can be fired with:

flux.track("conversion", { rev:'REVENUE' })

This will rely on cookies and current page URL to determine who the user is -- i.e. their visitor ID. For that visitor, the most recently created offer hit is what will be converted.

IMPORTANT NOTE

This event can only succeed if our global JS has already completed loading, so is best suited to events you may manually trigger after a page load, e.g. from a button click, form submit, etc.

If you try to use it immediately after our global JS -- to fire a conversion immediately on page load, it will often give a flux is not defined error as it is creating a race condition.

Our typical page view events in the global snippet earlier are triggered only once the JS completes loading, avoiding this.

If you do want to trigger a conversion immediately on page load, you should wrap the above code in an event listener and place it before our global JS.

See this document that details using our event listeners.

So an example code to place on the page would be:

document.addEventListener('fluxView', function() { 
  flux.track("conversion", { rev:'REVENUE' }) 
})

Additional Parameters

Additional data, if available, can be injected into the conversion event. 

The following parameters are available in conversion events:

  • rev -- revenue, optional, in dollars and cents e.g. 12.99. If omitted, the default for the converting offer is used.
  • tx -- transaction ID, optional
  • p -- page ID, optional, the ID of the offer (page) that the conversion should be attributed to. Often that is not the current page, but a previous page. If omitted, the most recent offer page view for the user's session will be converted
  • vid -- the visitor ID. This is often present in the URL or cookies, but can also be directly injected
  • hit -- the hit ID of the offer view to convert. This will usually not be the current page but a previous one. If this is known, you probably have all the info you need to instead for a more reliable server-to-server postback call. If you are sending hit, you should not send vid and vice versa, since they are user-identifiers that compete (hit is more specific and will get used).

For example a transaction ID and known page ID (of the offer that the conversion is associated with):

flux.track("conversion", { rev:'REVENUE', tx:'TRANSACTION_ID' p:'PAGE_ID' })

If a system can inject hit or visitor ID directly, this can also be done to make the tracking more reliable:

flux.track("conversion", { rev:'REVENUE', tx:'TRANSACTION_ID', vid:'VID', p:'PAGE_ID' })

The attribute hit can also be sent, though usually if you know hit ID, you can just call a postback URL instead. 

If hit ID and VID are known, you can pick to send one rather than both.

The API Request and Response

The API request sent will be similar to that for view events, for example:



If successful, the response will contain a conversion ID, timestamp and show the hit ID that converted, along with some event context:



Did this answer your question?