javascript BlueKai:VWO代码:TEMPLATE
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript BlueKai:VWO代码:TEMPLATE相关的知识,希望对你有一定的参考价值。
/*
################################################################
### ORACLE BLUEKAI : Universal Site Optimisation Integration ###
################################################################
Author : roshan.gonsalkorale@oracle.com, alex.wilton@oracle.com, mike.knott@oracle.com
Notes:
- This will query BlueKai for visitor profile data (campaign IDs and Category IDs) and send to a third party site optimisation platform
- Supported Services:
- Visual Website Optimiser (VWO) - Supplies category and campaign IDs in cookies ("bk_cat_ids" and "bk_campaign_ids")
- The code aims to dispatch BlueKai profile data to the third party system by either finding it via the BlueKai API or using a cookie copy
- It aims to call the third party system as quickly as possible
- All code is asynchronous
Debugger:
- add 'bk_so_logger=true' as a query-string parameter in the URL and check the console logs
Implementation Instructions:
- Host this code and run it in the <head> of your website
- Ensure the configuration options are set correctly
Code Workflow:
- Use the debugging to check the workflow
*/
window.bk_so_integration = window.bk_so_integration || {};
window.bk_so_integration.functions = window.bk_so_integration.functions || {};
window.bk_so_integration.data = window.bk_so_integration.data || {};
window.bk_so_integration.config = window.bk_so_integration.config || {};
// CONFIG : EDIT THIS PART
// BlueKai Config
window.bk_so_integration.config.bluekai_jsonreturn_id = "75725"; // replace with your JSON Return Container ID
window.bk_so_integration.config.wait_in_ms = 1; // How long to wait before asking BlueKai for the latest categories and firing data to third party (default 5000ms)
window.bk_so_integration.config.include_audience_names = false; // Set to true to share audience names to any vendors
// Vendor code : Visual Website Optimiser
window.bk_so_integration.config.enable_vwo = true; // set to true to enable integration
/*
* ##########################################################################################
* DO NOT EDIT BELOW THIS LINE
* ##########################################################################################
*/
// FUNCTION : Local Storage Send
bk_so_integration.functions.localstorage_cookie_sender = function(data, name_of_var) {
// Set data in first-party cookie if required
if(window.bk_so_integration.config.enable_cookie || window.bk_so_integration.config.enable_google_optimize || window.bk_so_integration.config.enable_vwo){
// encode cookie value if sending audience names
var cookie_data = (name_of_var === "bk_audience_names") ? encodeURIComponent(data).replace(/'/g,"%27").replace(/"/g,"%22") : data;
cookie_data = "," + cookie_data.join() + ",";
document.cookie = name_of_var + "=" + cookie_data + ";path=/;domain=." + location.hostname.split('.').reverse()[1] + "." + location.hostname.split('.').reverse()[0] + ";expires=Thu, 31 Dec 2099 00:00:00 GMT";
bk_so_integration.functions.logger("COOKIES : storing '" + JSON.stringify(cookie_data) + "' as '" + name_of_var
+ "' cookie");
}
}
// FUNCTION : Local Storage Retrieve
bk_so_integration.functions.localstorage_retriever = function(name_of_var) {
if (typeof (Storage) !== "undefined") {
var result = JSON.parse(localStorage.getItem(name_of_var));
if (!result) {
bk_so_integration.functions.logger("Local Storage : no " + name_of_var
+ " values available in local storage. Setting to empty array.");
return [];
}
bk_so_integration.functions.logger("Local Storage : Retrieved following '" + name_of_var
+ "' from local storage : " + result);
return result;
}
}
// FUNCTION : Local Storage fallback
bk_so_integration.functions.localstorage_fallback = function() {
bk_so_integration.functions.logger("Local Storage : attempting fallback");
// category IDs
if (typeof (Storage) !== "undefined") {
window.bk_so_integration.data.bk_category_ids = bk_so_integration.functions
.localstorage_retriever("bk_cat_ids");
window.bk_so_integration.data.bk_campaign_ids = bk_so_integration.functions
.localstorage_retriever("bk_campaign_ids");
if (window.bk_so_integration.config.include_audience_names) {
window.bk_so_integration.data.bk_audience_names = bk_so_integration.functions
.localstorage_retriever("bk_audience_names");
}
// Send data
bk_so_integration.functions.sendTargets();
} else {
bk_so_integration.functions.logger("LOCAL STORAGE : SEND DATA : HTML 5 NOT SUPPORTED");
return "no storage"; // HTML 5 NOT SUPPORTED
}
}
bk_so_integration.functions.logger = function(message, attribute_object) {
if (document.location.href.indexOf('bk_so_logger=true') > -1) {
// session cookie
document.cookie = "bk_so_logger=" + "true" + ";path=/;domain=" + document.domain + ";expires=";
}
if (document.cookie.indexOf('bk_so_logger=true') > -1) {
if (typeof attribute_object === "undefined") {
console.log("BLUEKAI SO : " + message);
} else {
for (varName in attribute_object) {
console.log("BLUEKAI SO : " + message + varName + "=" + attribute_object[varName]);
}
}
}
};
bk_so_integration.functions.arrayAddUnique = function(array, entry) {
if (array.indexOf(entry) < 0) {
array.push(entry);
}
}
// FUNCTION : Parse BlueKai data and send to targets
bk_so_integration.functions.parseBkResults = function() {
// Parse BlueKai Campaign Results
window.bk_so_integration.data.bk_category_ids = [];
window.bk_so_integration.data.bk_campaign_ids = [];
window.bk_so_integration.data.bk_audience_names = [];
if (typeof (bk_results) != "undefined") {
if (typeof (bk_results.campaigns[0]) != "undefined") {
bk_so_integration.functions.logger("'bk_results' object found");
for (var i = 0; i < bk_results.campaigns.length; i++) {
var campaignId = bk_results.campaigns[i].campaign
bk_so_integration.functions.arrayAddUnique(window.bk_so_integration.data.bk_campaign_ids, campaignId);
if (window.bk_so_integration.config.include_audience_names) {
var audience_name = bk_results.campaigns[i].BkDmpAudienceName;
if (typeof (audience_name) != "undefined") {
audience_name = decodeURIComponent(audience_name.replace(/\+/g, " ")); // decode URI
bk_so_integration.functions.logger("Audience name found: " + audience_name);
bk_so_integration.functions.arrayAddUnique(window.bk_so_integration.data.bk_audience_names,
audience_name)
}
}
for (var j = 0; j < bk_results.campaigns[i].categories.length; j++) {
if (typeof (bk_results.campaigns[i].categories[j].categoryID) != "undefined") {
var categoryId = bk_results.campaigns[i].categories[j].categoryID;
bk_so_integration.functions.arrayAddUnique(window.bk_so_integration.data.bk_category_ids,
categoryId);
}
}
}
// Send data to Local Storage
bk_so_integration.functions
.localstorage_cookie_sender(window.bk_so_integration.data.bk_category_ids, "bk_cat_ids");
bk_so_integration.functions.localstorage_cookie_sender(window.bk_so_integration.data.bk_campaign_ids,
"bk_campaign_ids");
if (window.bk_so_integration.config.include_audience_names) {
bk_so_integration.functions.localstorage_cookie_sender(window.bk_so_integration.data.bk_audience_names,
"bk_audience_names");
}
// Send data to targets
bk_so_integration.functions.sendTargets();
} else {
bk_so_integration.functions.logger("No campaigns object");
}
}
}
bk_so_integration.functions.sendTargets = function() {
}
// FUNCTION : Call BlueKai
bk_so_integration.functions.callBlueKai = function(bluekai_jsonreturn_id) {
1
// Check if JSON return tag and bk_results already there
if ((window.bk_results)
&& (document.head && document.head.innerHTML.indexOf(bluekai_jsonreturn_id + '?ret=js') > -1)
|| (document.body && document.body.innerHTML.indexOf(bluekai_jsonreturn_id + '?ret=js') > -1)) {
bk_so_integration.functions.logger("JSON Return tag found");
bk_so_integration.functions.logger("Parsing 'bk_results' directly");
bk_so_integration.functions.parseBkResults(); // Parse results (don't
// call JSON ret tag)
} else {
bk_so_integration.functions.logger("JSON Return tag NOT found");
//bk_so_integration.functions.localstorage_fallback(); // Grab from
// local storage
bk_so_integration.functions.logger("Waiting " + window.bk_so_integration.config.wait_in_ms
+ "ms before calling JSON Return Tag");
setTimeout(function() {
bk_so_integration.functions.logger("Calling JSON Return tag");
var bk_json_ret = document.createElement("script");
bk_json_ret.type = "text/javascript";
bk_json_ret.onload = function() {
bk_so_integration.functions.logger("JSON Return tag loaded");
bk_so_integration.functions.logger("Parsing 'bk_results'");
bk_so_integration.functions.parseBkResults(); // Parse results
};
bk_json_ret.src = "//tags.bluekai.com/site/" + bluekai_jsonreturn_id
+ "?ret=js&limit=1&phint=integration=so";
document.head.appendChild(bk_json_ret);
}, window.bk_so_integration.config.wait_in_ms);
}
};
// CONFIG LOGGING : Loop through config and log
for (configs in window.bk_so_integration.config){
bk_so_integration.functions.logger("CONFIG : " + configs + " = " + window.bk_so_integration.config[configs]);
}
// RUN CODE
bk_so_integration.functions.callBlueKai(window.bk_so_integration.config.bluekai_jsonreturn_id);
以上是关于javascript BlueKai:VWO代码:TEMPLATE的主要内容,如果未能解决你的问题,请参考以下文章
javascript BlueKai API Caller(Javascript)
javascript BlueKai CoreTag - 付费与自然搜索