roshanoracle
3/16/2018 - 11:37 AM

Condenast - Facebook Custom Audience Pixel (GQ UK)

For BlueKai Tag Management

<script type="text/javascript">
// Facebook Custom Audience Pixel
(function(){

	// Set up (do not change)
	var custom_params = [];

	// Config (change)
	var pixel_id = 1294144300667414; // change to your pixel ID
	var event_name = "BlueKai Tracking"; // change to your event name
	var grab_all_phints = true; // Set to false if you don't want to send all phints to Facebook

	// Custom Parameters : specify any additional custom parameters you would like
	custom_params.push(["website","Roshan Website"]); // e.g. for single values ["content_name","article"]	

	// ### DO NOT EDIT BELOW THIS LINE ###

	var ts = Math.round((new Date()).getTime() / 1000);
	var cacheBust = parseInt(Math.random()*10000000000);
	var fb_url = "//www.facebook.com/tr/?id=" + pixel_id + "&ev=" + encodeURIComponent(event_name) + "&ts=" + ts + "&dl=" + encodeURIComponent(document.referrer) + "&cb=" + cacheBust + "&";

	if (grab_all_phints){
	
		var phints = {};
		var url_args = document.location.search.split("&");

		for (var i = 0; i < url_args.length; i++) {
			
			if(url_args[i].indexOf("phint=") === 0){

				var phint_name = url_args[i].split("phint=")[1].split("%3D")[0];

				var phint_value = decodeURIComponent(url_args[i].split("phint=")[1].split("%3D")[1]);

				if (phints[phint_name]){
					phints[phint_name].push(phint_value)

				} else {

					phints[phint_name] = [phint_value]
				}
			}
		}
	
		for (phint_name in phints){

			if(phints[phint_name].length === 1){

				custom_params.push([phint_name,phints[phint_name][0]]);

			} else {

				custom_params.push([phint_name,phints[phint_name]]);

			}

		}

	}

	var fbCustomParams = [];	
	
	for (var i = 0; i < custom_params.length; i++) {


		// var name
		var key_value_pair = "cd[" + encodeURIComponent(custom_params[i][0]) + "]=";

		if(typeof custom_params[i][1] === "object" && custom_params[i][1].length > 1){
	
			key_value_pair += encodeURIComponent("[" + custom_params[i][1].join(",") + "]");
		

		} else {

			key_value_pair += encodeURIComponent(custom_params[i][1]);
		}
		

		fbCustomParams.push(key_value_pair);
	}


	fb_url += fbCustomParams.join("&");
	
	var fbPixel = new Image();
	fbPixel.height = '1';
	fbPixel.width = '1';
	fbPixel.src = fb_url;

})();
</script>