-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.etracker-smartmessage.js
65 lines (59 loc) · 2.19 KB
/
jquery.etracker-smartmessage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
** etracker smart messaging component
*/
(function($){
$.extend({
etrackerSmartMessage: function(options){
var ret = {};
var etrackerOptions = {
'targeting' : {
collector : function(dataCallback) {
function getCoidCookie() {
var value = "; " + document.cookie;
var parts = value.split("; _et_coid=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
var apiHost = options.targeting.config.targetingAPIHost ? options.targeting.config.targetingAPIHost : '//ws.etracker.com';
var url = apiHost+'/api/rest/v2/realtime/user?et='+options.targeting.config.secureCode;
url += '&_et_coid='+getCoidCookie()+'&callback=?';
$.getJSON(url, {}).done(function( targetingData ) {
var formatedData = [];
for(headerNum in targetingData['header'] || [])
{
formatedData[targetingData['header'][headerNum]] = targetingData['data'][headerNum];
}
dataCallback(formatedData);
}).fail(function(){
dataCallback({});
});
}
},
tracking : function(actionType, configuration) {
var etrackerSecureCode = $('#_etLoader').attr('data-secure-code');
if(
etrackerSecureCode != '' &&
$.isFunction(window.et_cc_wrapper) &&
(actionType == 'view' || actionType == 'click'))
{
var triggerNames = {
'exitIntent' : 'STC_CC_ATTR_VALUE_TRIGGER_EXIT_INTENT',
'greeter' : 'STC_CC_ATTR_VALUE_TRIGGER_GREETER',
'attentionGrabber' : 'STC_CC_ATTR_VALUE_TRIGGER_ATTENTION_GRABBER'
};
window.cc_attributes = {
'etcc_cmp' : [configuration.name, true],
'etcc_cty' : ['STR_CC_PROJECT_TYPE_SMART_MESSAGING', true],
'etcc_int' : [actionType, true],
'etcc_trg' : [triggerNames[configuration.trigger.type] ? triggerNames[configuration.trigger.type] : 'none', true],
'universe' : [6, true]
};
window.et_cc_wrapper(etrackerSecureCode);
}
}
};
ret.etrackerCollector = etrackerOptions.targeting.collector;
ret.etrackerTracking = etrackerOptions.tracking;
var config = $.extend(true, etrackerOptions, options);
return $.extend(ret, $.smartMessage(config));
}});
})(jQuery);