SubID tracking is a useful tool that can be customized to achieve your reporting needs. Some of the ways Publishers successfully utilize SubID tracking include tracking revenue by geo, article, traffic source, social influencer, or to evaluate performance on different page variations.

Adding SubID Tracking to Your Widget(s)

In order to start collecting SubID data you'll need to add a "data-sub-ids" array along with your custom key-value pairs into your widget script like we've done in the following example:

<div id="habitat" 
    data-rc-widget
    data-widget-host="habitat"
    data-endpoint="trends.revcontent.com"
    data-widget-id=“000000"
    data-sub-ids='{"KEY1":"VALUE1","KEY2":"VALUE2"}'></div>
<script type="text/javascript" src="//assets.revcontent.com/master/delivery.js" defer="defer"></script>

Retrieving SubID Stats

In order to pull SubID reports you must have a 3rd party API software. We recommend Postman which is free to use.

The API request used to pull SubID reports can be found here in our API Documentation: Widget - Get SubID Stats

Optional Advanced Usage - Extracting SubIDs from URLs

The following examples are optional advanced methods which would allow SubIDs to be pulled directly from URLs.

The first is ES6 which is compatible with Chrome, FireFox, Edge, however not Internet Explorer:

//ES6
let el = document.getElementById('habitat');
let subids = {};
let params = new URLSearchParams(window.location.search);
for ( const [key, value] of params) {
  subids[key] = value;
}
el.setAttribute('data-sub-ids', JSON.stringify(subids));

The second is conventional Javascript which is compatible across all browsers but is a bit more involved: 

//Vanilla JS
function getParams() {
  var params = {};
  var query = window.location.search ? window.location.search.slice(1) : null;
  if (query) {
    var arr = query.split('&')
    for (var i = 0; i < arr.length; i++) {
      var entry = arr[i].split('=');
      params[entry[0]] = entry[1];
    }
  }
  return params;
}
var subids = getParams();
el.setAttribute('data-sub-ids', JSON.stringify(subids));

The logic above can be updated to get meta tags or any other unique values and serves as a general guideline for working with SubIDs outside of setting them directly on the div. As an example, if you were using the following params:
&rc_campaign=value1&utm_source=value2
The objects returned would be:
subids = { rc_campaign: value1, utm_source: value2 } 

Did this answer your question?