How to use API to send personalised Push Notifications?

1. Pass data about userID to MaxTraffic tracking code

If your website ID is 1234, then by default MaxTraffic tracking code will look like this:

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

To use API, you need to customize the MaxTraffic tracking code by setting userId parameter:

mt('set', 'userId', '123456789');

So if your website visitor is logged in and you know his userId, then tracking code will look like this:

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

Don't forget to replace 1234 with your website ID, and 123456789 with userId.

Note: if you don't know the userId (for example, user is not logged in), then use the default tracking code version (without setting the userId parameter).

2. Get your API key

You can get your API key in Push Notifications > Settings > API:

3. Use REST API

Check out documentation here: dev.maxtraffic.com

Right now API has 2 features:

  • check if a specific user has subscribed to notifications¬†
  • send personalised notification to 1 or more users by specifying their userID's.

If something is not clear, please write to support@maxtraffic.com