Saving user ID in MaxTraffic

For many automations to work, you will need to connect your system's user ID with MaxTraffic.

To do that, you need to use following JavaScript code. This example assumes that you are using Google Tag Manager and have created a user_id variable that contains your system's user ID.

<script>
//get user id
var mt_user_id = parseInt({{user_id}}) || null;

if(mt_user_id) {
    //save user id
    mt('set', 'userId', mt_user_id);
}
</script>

We recommend to add this code at the end of MaxTraffic tracking code. The default tracking code looks like this:

<script>
  window.mt=window.mt||function(){(mt.q=mt.q||[]).push(arguments)};mt.l=+new Date;
  mt('create', 12345);
</script>
<script async src="//cdn.mxapis.com/mt.js"></script>

If you add the part about saving user ID, then everything together should look similar to this example:

<script>
window.mt=window.mt||function(){(mt.q=mt.q||[]).push(arguments)};mt.l=+new Date;
  mt('create', 12345);
</script>
<script async src="//cdn.mxapis.com/mt.js"></script>

<script>
//get user id
var mt_user_id = parseInt({{user_id}}) || null;

if(mt_user_id) {
  //save user id
  mt('set', 'userId', mt_user_id);
}
</script>

Important:

  • Replace 12345 with your website ID
  • Replace {{user_id}} with the GTM variable you use for user ID