javascript Engie:Allomedia BKUUID Grabber

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Engie:Allomedia BKUUID Grabber相关的知识,希望对你有一定的参考价值。

/*
######################
### BKUUID GRABBER ###
######################
 
Author : roshan.gonsalkorale@oracle.com
 
Pre-requisites:
 
- Site Optimisation Container in Partner Seat
- Push Delivery must be enabled in seat
- Campaign must be created targeting all 1st party taxonomy and JSON return enabled
- Campaign must have $_BK_UUID and $_BK_UUID_NOSLASH macros pushed as "BKUUID" and "BKUUID_noslash" in respective order
- Only works for HTML5 compliant browsers
- Has config to alllow you to restrict the number of calls per session (controlled via cookie - 2 recommended)
 
Instructions :
 
- Complete config below
- Implement anywhere in page (it will run asynchronously and grab the BKUUID from the JSON return response if present)
- Will work in Tag Managers or directly on site
 
*/
 
// ### CONFIG ###
var site_optimisation_tag_id = 56370; // replace with JSON Return container ID
var bkuuid_varname = "BKUUID"; // replace with name for BKUUID name in JSON campaign
var bkuuid_noslash_varname = "BKUUID_noslash"; // replace with name for BKUUID_noslash name in JSON campaign
var max_calls_per_session = 2; // Set to "all" to call BlueKai on every page view. Otherwise set to limit of calls per session (recommended 2)
 
// Declare Global Object
window.bluekai_service = window.bluekai_service || {};
bluekai_service.functions = bluekai_service.functions || {};
window.bluekai_service.bkuuid_caller = window.bluekai_service.bkuuid_caller || {};

// ### FUNCTIONS ###

// FUNCTION : Site Optimisation Tag Caller
bluekai_service.functions.site_optimisation_call = function(){

	max_calls_per_session++ // normalise

	// Cancel call if exceeds max calls per session
	if(window.bluekai_service.bkuuid_caller.calls > max_calls_per_session){return;} 

	bluekai_service.bk_json_ret = document.createElement("script");
	bluekai_service.bk_json_ret.type = "text/javascript";
	bluekai_service.bk_json_ret.onload = function() {
		
		bluekai_service.functions.parseBkResults(); // Parse results
	};
 
	bluekai_service.bk_json_ret.src = "//tags.bluekai.com/site/" + site_optimisation_tag_id + "/?ret=js&limit=1&phint=tag_type=bkuuid_grabber";
	document.head.appendChild(bluekai_service.bk_json_ret); // Call Tag
};
 
// FUNCTION : Site Optimisation Tag Parser
bluekai_service.functions.parseBkResults = function() {
 
	if (typeof bk_results === "object" && typeof bk_results.campaigns === "object") {
 
		for (var i = 0; i < bk_results.campaigns.length; i++) {
 
			if (bk_results.campaigns[i][bkuuid_varname]) {
 
				BKUUID = bk_results.campaigns[i][bkuuid_varname];
				bluekai_service.functions.localstorage_sender(BKUUID,"BKUUID"); // Send to local storage
 
				var kill = true;
			}
 
			if (bk_results.campaigns[i][bkuuid_noslash_varname]) {
 
				BKUUID_noslash = bk_results.campaigns[i][bkuuid_noslash_varname];
				bluekai_service.functions.localstorage_sender(BKUUID_noslash,"BKUUID_noslash"); // Send to local storage
 
				var kill = true;
			}
 
			if (kill) {
				break;
			}
		}
	}
 
};
 
// FUNCTION : Local Storage Retriever
bluekai_service.functions.localstorage_retriever = function(name_of_var) {
 
	if (typeof(Storage) !== "undefined") {
 
		var result = JSON.parse(localStorage.getItem(name_of_var));
		if (!result) {
 
			//	bluekai_service.functions.logger("Local Storage : no " + name_of_var + " values available in local storage. Setting to empty array.");
 
			return [];
		}
 
		//bluekai_service.functions.logger("Local Storage : Retrieved following '" + name_of_var + "' from local storage : " + result);
 
		return result;
	}
 
};

// FUNCTION : Local Storage Sender 
bluekai_service.functions.localstorage_sender = function(data, name_of_var) {
 
	if (typeof(Storage) !== "undefined") {
 
		//bluekai_service.functions.logger("LOCAL STORAGE : storing '" + JSON.stringify(data) + "' as '" + name_of_var + "' in local storage");
		localStorage.setItem(name_of_var, JSON.stringify(data));
 
	} else {
 
		//bluekai_service.functions.logger("LOCAL STORAGE : SEND DATA : HTML 5 NOT SUPPORTED");
		return "no storage"; // HTML 5 NOT SUPPORTED
	}
 
};

// FUNCTION : Call Counter
bluekai_service.functions.bkuuid_grabber_cookie = function(){
	
	if(document.cookie.indexOf("BKUUID_GRABBER=") > -1){

		// detect number of calls made and increment by one then update cookie
		var calls = parseInt(document.cookie.split("BKUUID_GRABBER")[1].charAt(1));
		calls++  // increment by one
		document.cookie = "BKUUID_GRABBER=" + calls + ";path=/;domain=" + document.domain + ";expires=";
		return calls;

	} else {

		document.cookie = "BKUUID_GRABBER=" + "1" + ";path=/;domain=" + document.domain + ";expires=";
		return 1;

	}
};

// ### EXECUTION ###

// Count calls
window.bluekai_service.bkuuid_caller.calls = bluekai_service.functions.bkuuid_grabber_cookie();

// Execute all code
bluekai_service.functions.site_optimisation_call();

以上是关于javascript Engie:Allomedia BKUUID Grabber的主要内容,如果未能解决你的问题,请参考以下文章

html Engie - A / B美味 - 网站优化标签

html Engie:iOS / Android App Pixel

html Engie ID_PERS查询字符串Grabber

《前端开发核心知识进阶》抽奖送书!

NHOA计划获得2.3亿欧元的新财务资源,以实现Masterplan10x计划和战略目标

Denodo的另一场大规模年度用户大会圆满落幕,共吸引来自北美欧洲中东非洲及亚太区的5000名用户参加