This repository has been archived by the owner on Apr 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.omniturecontroller.js
111 lines (87 loc) · 2.27 KB
/
jquery.omniturecontroller.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(function($){
// extends jquery to delegate callbacks to objects.
$.extend({
scope: function(fn, scope)
{
return function(){
return fn.apply(scope, arguments);
}
}
});
$.fn.OmnitureController = function($library,$scode){
var $self = $(this),
$jq = $,
tracker,
_library,
_s;
$library ? _library = $library : _library = window.library;
$scode ? _s = $scode: _s = window.s;
function init(){
alert("controller init");
// instantiate tracker
tracker = new mry.analytics.Omniture(_library,_s);
// get the page load item and send it
var b = $self.find("[data-omni-page]");
var oid = b.attr("data-omni-page");
if(oid !== undefined){
var params = b.attr("data-omni-params");
if(params !== undefined){
var obj = createCustomEvent(oid,params);
tracker.send(obj);
} else {
tracker.sendId(oid);
}
}
// set up clicks
$self.find("[data-omni]").click(jQuery.scope(onItemClick,this));
//$self.click(jQuery.scope(onItemClick,this));
}
function onItemClick($e){
var $this = $($e.currentTarget),
oid = $this.attr("data-omni"),
params = $this.attr("data-omni-params"),
href = $this.attr("href");
console.log("oid:" + oid);
// if it's an <a> tag override the click
// to make sure the event fires
if(href !== undefined){
var targ = $this.attr("target");
$e.preventDefault();
setTimeout(function(){
if (targ !== undefined && targ === "_blank") {
window.open(href);
} else {
window.location = href;
}
},100);
}
if(params !== undefined){
var obj = createCustomEvent(oid,params);
tracker.send(obj);
} else {
tracker.sendId(oid);
}
}
function writeParams($str,$paramsArray){
var x,
params = $paramsArray,
l = params.length,
param;
for(x=0;x<l;x++){
param = params[x];
$str = $str.split("[" + (x + 1) + "]").join(param);
}
return $str;
}
// add custom parameters to event before sending
function createCustomEvent($id,$paramsString){
var obj = tracker.getItem($id);
var params = $paramsString.split(",");
for(var i in obj){
obj[i] = writeParams(obj[i],params);
}
return obj;
}
init();
}
})(jQuery);