Getting dynamic data using our Javascript (V1)

Avatar

By Zeno

updated 3 months ago

Please note -- we have now released a version 2 Javascript tracking code and API. This documentation is kept since users may still have the old JS in use. Do not use this documentation if you are implementing JS tracking for the first time.

In your lander/offer URLs you can use {tokens} to pass data, right?

You can do the same with our JS, to get data like user country, city, ISP, device, etc. all from your page without needing redirects.

This is very easy to do, though you may need some JavaScript skills to do things with that data later (we will leave that to you, though will provide some examples in other documents).

To do this, you can use the resolveTokens option in the JS, for example:

lum.event('view', {
     'query': {  
         'p': 'SOME_VALUE',
     },
     'options': { 
      'cookieAllowed': true, 
      'timeOnPage': false, 
      'resolveTokens': ['{brand}', '{isp}', '{country-name}'], 
    },
     'onDone': function(response) {}
 });

Here we can add comma-separated list of tokens inside quotes and they will be returned in the JS response, along with visitor ID (vid), which is always returned.

Need a list of tokens? See HERE.

The JS response might then look like this:

{
    "error": "",
    "resolvedTokens":
    {
        "{brand}": "Unknown",
        "{isp}": "True internet co. ltd.",
        "{country-name}": "Thailand",
        "{visitor}": "ftSV2K6sbER62yTdpdjhOPmnqx"
    },
    "skv": "vid"
}

If you want to make things easy, in our JS you can set all of these token values to JavaScript variables in our onDone function, like so:

lum.event('view', {
     'query': {  
         'p': 'SOME_VALUE',
     },
     'options': { 
      'cookieAllowed': true, 
      'timeOnPage': false, 
      'resolveTokens': ['{brand}', '{isp}', '{country-name}'], 
    },
     'onDone': function(response) {
           var vid = response.resolvedTokens['{visitor}'];
           var brand = response.resolvedTokens['{brand}'];
           var isp = response.resolvedTokens['{isp}'];
           var country = response.resolvedTokens['{country-name}'];
           //and do some other stuff?
     }
 });
});

This onDone function is very useful as it lets you execute JavaScript only after our tracking has finished -- i.e. its a callback function.

If you want to update data on the page to use dynamic token data, either put that JS code in our onDone function, or better yet make some other functions on your page that take in our data as parameters, then call the function from our onDone section.

Did this answer your question?