roshanoracle
3/14/2019 - 5:09 PM

Paysafe : BlueKai CoreTag : GTM Suggested Code

<!-- 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;

	// PII Bad Char List
	var pii_bad_chars = ["@"]; // Will not allow data to be sent if it contains one of these chars

	// FUNCTION : pii_cleaner()

	// e.g. pii_cleaner("{{event_label}}",["@"]);
	function pii_cleaner (varValue,badStrings){

		var toType = function(obj) {
			return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
		}
		
		if(badStrings && toType(badStrings) == "string"){
			if(varValue.indexOf(badStrings) > -1){
				return "potential pii (" + badStrings + ") - value killed";
			} else{
				return varValue;
			}
		} else if(badStrings && toType(badStrings) === "array"){

			let kill = false;
			var detected_bad_strings = [];	

			for (var i = 0; i < badStrings.length; i++) {

				let badString = badStrings[i];
				
				if(varValue.indexOf(badString) > -1){
					kill = true;
					detected_bad_strings.push(badString);
				}
			}

			if(kill){return "potential pii (" + detected_bad_strings.join(",") + ") - value killed";}else{
				return varValue;
			}

		} else{
			return "pii_cleaner() not correctly formed. Data stripped for safety";
		}
	}

	//FUNCTION : declarePhint()
	// e.g. declarePhint("page_name",{{page_name}});
	declarePhint = function(varName,dataLayerVar){

		if(dataLayerVar){

			// PII Stripping : start
			var toType = function(obj) {
				return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
			}

			var returnValue = dataLayerVar;

			if(typeof pii_bad_chars !== "undefined" && pii_bad_chars && toType(pii_bad_chars) == "string"){
				
				if(dataLayerVar.indexOf(pii_bad_chars)>-1){
					returnValue = "potential pii found (" + pii_bad_chars + ") - data removed";
				}
			} else if(typeof pii_bad_chars !== "undefined" && pii_bad_chars && toType(pii_bad_chars) === "array"){

				var detected_bad_strings = [];
				var kill = false;
				for (var i = 0; i < pii_bad_chars.length; i++) {
					
					let pii_char = pii_bad_chars[i];

					if(dataLayerVar.indexOf(pii_char)>-1){
						kill = true;
						detected_bad_strings.push(pii_char);
						
					}
				}
				if(kill){
					returnValue = "potential pii found (" + detected_bad_strings.join(",") + ") - data removed";
				}
			}

			// PII Stripping : start
			bk_addPageCtx(varName, returnValue);

		}

	}

	// Declare vars
	declarePhint('page_name','{{page_name}}');
	declarePhint('customer_id','{{customer_id}}');
	// ...etc...
	
	// Grab Query-String Parameters // grab from urlP["nameofparameter"], e.g. urlP["email_id"]
	var urlP;
	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.search.substring(1);

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

	// whitelist params ("starts with") (add more params to this list)
	qsp_whitelist = ["utm_"];

	// query-string param grabber
	for (qsp in urlP){

		for (var i = 0; i < qsp_whitelist.length; i++) {
			
			if (qsp.indexOf(qsp_whitelist[i]) === 0){
				
				bk_addPageCtx('qsp_' + qsp, urlP[qsp]);

			}
		}

	}



	// Send Data 
	BKTAG.doTag(ENTER CONTAINER ID HERE, 4);

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

	// PII Bad Char List
	var pii_bad_chars = ["@"]; // Will not allow data to be sent if it contains one of these chars

	// FUNCTION : pii_cleaner()

	// e.g. pii_cleaner("{{event_label}}",["@"]);
	function pii_cleaner(c,a){var b=function(g){return{}.toString.call(g).match(/\s([a-zA-Z]+)/)[1].toLowerCase()};if(a&&"string"==b(a))return-1<c.indexOf(a)?"potential pii ("+a+") - value killed":c;if(a&&"array"===b(a)){b=!1;for(var e=[],d=0;d<a.length;d++){var f=a[d];-1<c.indexOf(f)&&(b=!0,e.push(f))}return b?"potential pii ("+e.join(",")+") - value killed":c}return"pii_cleaner() not correctly formed. Data stripped for safety"};

	//FUNCTION : declarePhint()
	// e.g. declarePhint("page_name",{{page_name}});
	declarePhint=function(g,b){if(b){var a=function(h){return{}.toString.call(h).match(/\s([a-zA-Z]+)/)[1].toLowerCase()},c=b;if("undefined"!==typeof pii_bad_chars&&pii_bad_chars&&"string"==a(pii_bad_chars))-1<b.indexOf(pii_bad_chars)&&(c="potential pii found ("+pii_bad_chars+") - data removed");else if("undefined"!==typeof pii_bad_chars&&pii_bad_chars&&"array"===a(pii_bad_chars)){a=[];for(var e=!1,d=0;d<pii_bad_chars.length;d++){var f=pii_bad_chars[d];-1<b.indexOf(f)&&(e=!0,a.push(f))}e&&(c="potential pii found ("+
a.join(",")+") - data removed")}bk_addPageCtx(g,c)}};

	// Declare vars
	declarePhint('page_name','{{page_name}}');
	declarePhint('customer_id','{{customer_id}}');
	// ...etc...
	
	// Grab Query-String Parameters // grab from urlP["nameofparameter"], e.g. urlP["email_id"]
	var urlP;
	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.search.substring(1);

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

	// whitelist params ("starts with") (add more params to this list)
	qsp_whitelist = ["utm_"];

	// query-string param grabber
	for (qsp in urlP){

		for (var i = 0; i < qsp_whitelist.length; i++) {
			
			if (qsp.indexOf(qsp_whitelist[i]) === 0){
				
				bk_addPageCtx('qsp_' + qsp, urlP[qsp]);

			}
		}

	}



	// Send Data 
	BKTAG.doTag(ENTER CONTAINER ID HERE, 4);

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