To track whitelisted users’ contribution to revenue in the ad server we will be utilizing the ability to send and report on key-value pairs in the ad server.
The code update below uses the Sourcepoint client data callback function to set a cookie to be later retrieved on a subsequent pageview with the key-value pair being sent to the ad server as a targeting parameter.
The cookie setter function (sp_setCookie) can be replaced by the site’s cookie setter function or leverage jQuery's $.cookie() to achieve the same result.
window._sp_.config.mms_client_data_callback = function(o) {var _sp_msg_id = parseInt(o.info.msg_id);var _sp_cookie_val = "";if(o.d.abp==true && _sp_msg_id>0){sp_setCookie("sp","whitelist",365);}};function sp_setCookie(cname, cvalue, exdays) {var d = new Date();d.setTime(d.getTime() + (exdays*24*60*60*1000));var expires = "expires="+ d.toUTCString();document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";}
For illustration purposes, we are using key-value pair capabilities of DFP. The code below will retrieve the sp cookie using the sp_getCookie function. Sites can and will most likely use their own cookie retrieval function.
Once the cookie value is stored in a JavaScript variable it can be passed to the ad server using the ad server’s standard key-value pair targeting functionality. In this example, we are showing DFP’s googletag.pubads().setTargeting() call.
This enables reporting and targeting in the DFP ad serving platform.
<script>function sp_getCookie(cname) {var name = cname + "=";var decodedCookie = decodeURIComponent(document.cookie);var ca = decodedCookie.split(';');for(var i = 0; i <ca.length; i++) {var c = ca[i];while (c.charAt(0) == ' ') {c = c.substring(1);}if (c.indexOf(name) == 0) {return c.substring(name.length, c.length);}}return "";}var sp_cookie_val = "";sp_cookie_val = sp_getCookie(cname); googletag.cmd.push(function() {googletag.defineSlot("/1234/travel/asia", [728, 90], "div-gpt ad-123456789-0").addService(googletag.pubads()).setTargeting("interests", ["sports", "music", "movies"]);googletag.pubads().setTargeting("topic","basketball");googletag.pubads().setTargeting("sp",sp_cookie_val);googletag.pubads().enableSingleRequest();googletag.enableServices();});</script>
Ad servers may require you to whitelist the key-value pair before it is available for reporting in the ad server. The screenshot below shows this in DFP.
Sending data to your site analytics platform also leverages the mms_client_data_callback function.
window ._sp_.config.mms_client_data_callback = function (data) {// do something useful with the dataObjectvar ab_state = data.d.abp;var campaign_id = data.info.cmpgn_id;var message_id = data.info.msg_id; //Send data to external platform}; window ._sp_.config.mms_choice_selected_callback = function (choiceID) {var choice_made =choiceID;//Send data to external platform};