roshanoracle
6/17/2019 - 2:57 PM

BlueKai CoreTag - Advanced URL + query-string parameter grabber

<!-- Begin BlueKai Tag -->
<script type="text/javascript">
window.bk_async = function() {

 // ALLOW MULTIPLE CALLS/SINGLE PAGE APPS
bk_allow_multiple_calls=true; bk_use_multiple_iframes=true;

	// <optional> PHINTS : Declare variables about this page (or user)

	bk_addPageCtx('url_1', document.location.href);
	bk_addPageCtx('url_2', document.location.href);
	bk_addPageCtx('path_1', document.location.pathname);
	bk_addPageCtx('path_2', document.location.pathname);
	
	// Grab all query-string parameters and declare as phints
	var urlParams;
	var match,
		pl = /\+/g, // Regex for replacing addition symbol with a space
		search = /([^&=]+)=?([^&]*)/g,
		decode = function(s) {
			return decodeURIComponent(s.replace(pl, " "));
		},
		query = (window.location.href.split('?')[1]) ? window.location.href.split('?')[1] : "";

	urlParams = {};
	while (match = search.exec(query))
		urlParams[decode(match[1])] = decode(match[2]);

	for (varName in urlParams) {

		bk_addPageCtx("qsp_" + varName, urlParams[varName]);
	}


	// Send Data 
	BKTAG.doTag(123456, 4); // Replace 123456 with Container ID

};
(function() {
  var scripts = document.getElementsByTagName('script')[0];
  var s = document.createElement('script');
  s.async = true;
  s.src = "https://tags.bkrtx.com/js/bk-coretag.js";
  scripts.parentNode.insertBefore(s, scripts);
}());
</script>
<!-- End BlueKai Tag -->