Skip to content

Instantly share code, notes, and snippets.

@weburnit
Created May 10, 2020 16:29
Show Gist options
  • Save weburnit/9807cfed1a2b01afd352bc671c73e97e to your computer and use it in GitHub Desktop.
Save weburnit/9807cfed1a2b01afd352bc671c73e97e to your computer and use it in GitHub Desktop.
Tracking
var path = location.pathname + location.hash;
var opts = {
scope: 'ecommerce',
url: 'http://localhost:8000'
};
window.follower || (window.follower = {});
(function () {
var follower_queue = [];
var methods = ['trackSubmit', 'trackClick', 'trackLink', 'trackForm', 'initialize', 'pageview', 'identify', 'reset', 'group', 'track', 'ready', 'alias', 'debug', 'page', 'once', 'off', 'on', 'personalize'];
var factory = function (method) {
return function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
follower_queue.push(args);
return window.follower;
};
};
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
window.follower[method] = factory(method);
}
function callback(e) {
follower.initialize({
'Apache Unomi': opts
});
while (follower_queue.length > 0) {
var item = follower_queue.shift();
var method = item.shift();
if (follower[method]) {
follower[method].apply(follower, item);
}
}
}
follower.load = function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = opts.url + '/tracker/unomi-tracker.min.js';
if (script.addEventListener) {
script.addEventListener('load', function (e) {
if (typeof callback === 'function') {
callback(e);
}
}, false);
} else {
script.onreadystatechange = function () {
if (this.readyState === 'complete' || this.readyState === 'loaded') {
callback(window.event);
}
};
}
var first = document.getElementsByTagName('script')[0];
first.parentNode.insertBefore(script, first);
};
document.addEventListener('DOMContentLoaded', follower.load);
})();
follower.page(opts.initialPageProperties);
follower.personalize({
"id": "testPersonalization",
"strategy": "matching-first",
"strategyOptions": {
"fallback": "var2"
},
"contents": [
{
"id": "var1",
"filters": [
{
"condition": {
"type": "booleanCondition",
"parameterValues": {
"operator": "and",
"subConditions": [
{
"type": "profilePropertyCondition",
"parameterValues": {
"propertyName": "properties.nbOfVisits",
"comparisonOperator": "greaterThanOrEqualTo",
"propertyValueInteger": 1
}
},
{
"parameterValues": {
"minimumDuration": 5,
"maximumDuration": 360000
},
"type": "sessionDurationCondition"
}
]
}
}
}
]
},
{
"id": "var2"
}
]
}, function (res) {
console.log(res);
document.getElementById(res[0]).style.display = 'block';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment