You may wish to show content with a different rating to visitors from different sources of traffic or track certain sources separately in reports. You can do this by setting up different widgets for each desired source and using a simple JavaScript conditional statement to switch between widgets with the desired settings.

  1. In addition to the default widget, create and configure an additional widget for each traffic source that requires separate settings or tracking.
  2. Ensure that visitors from the desired traffic sources are using URLs with a parameter unique to that source.
    http://example.com?utm_source=adsinc
  3. Add JavaScript to your page that swaps the widget ID and unique ID in the needed places based on the unique parameter.  In the example below, a specific widget is displayed for traffic from “adsinc”, while the default widget is used for all other traffic:
    <div id="contentad[Default widget WID value]"><!-- Load Widget Here --></div>
    <div id="contentad[Adsinc widget WID value]"><!-- Load Widget Here --></div>
    <script type="text/javascript">
        (function(d) {
            /* Add function for parsing URL parameters */
            function getURLParameter(name) {
                return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
            }
    
            /* Get the value of utm_source from the URL */
            var trafficSource = getURLParameter('utm_source');
    
            /* If utm_source isn't set, try to get it from web storage */
            if (!(trafficSource)) {
                if (sessionStorage.trafficSource) {
                    trafficSource = sessionStorage.trafficSource;
                }
            }
    
            /* Save the source in web storage */
            sessionStorage.trafficSource = trafficSource;
    
            /* Define the default widget */
            var cad_id = "[Default widget unique ID value]";
            var cad_wid = "[Default widget WID value]";
            var cad_did = "[Your D value]";
    
            /* If utm_source is adsinc, swap widget */
            if (trafficSource == "adsinc") {
                var cad_id = "[Adsinc widget unique ID value]";
                var cad_wid = "[Adsinc widget WID value]";
            }
    
            /* Add the parameters to the widget installation code so that the correct widget is displayed*/
            var params =
            {
                id: cad_id,
                d: cad_did,
                wid: cad_wid,
                cb: (new Date()).getTime()
            };
    
            var qs=[];
            for(var key in params) qs.push(key+'='+encodeURIComponent(params[key]));
            var s = d.createElement('script');s.type='text/javascript';s.async=true;
            var p = 'https:' == document.location.protocol ? 'https' : 'http';
            s.src = p + "://api.content.ad/Scripts/widget2.aspx?" + qs.join('&');
            d.getElementById("contentad" + cad_wid).appendChild(s);
        })(document);
    </script>
    

You may use an ad server to control the swapping logic instead.  You can write server-side code to perform this action as well, but this may not work as needed when page caching is enabled.

If you have a support question or bug report, please contact our support team.