-
Notifications
You must be signed in to change notification settings - Fork 0
/
gas-1.10.1.js
1762 lines (1619 loc) · 51.3 KB
/
gas-1.10.1.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @preserve Copyright 2011, Cardinal Path and DigitalInc.
*
* GAS - Google Analytics on Steroids
* https://github.com/CardinalPath/gas
*
* @author Eduardo Cereto <[email protected]>
* Licensed under the GPLv3 license.
*/
(function(window, undefined) {
/**
* GAS - Google Analytics on Steroids
*
* Helper Functions
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the MIT license.
*
* @author Eduardo Cereto <[email protected]>
*/
/**
* GasHelper singleton class
*
* Should be called when ga.js is loaded to get the pageTracker.
*
* @constructor
*/
var GasHelper = function () {
this._setDummyTracker();
};
GasHelper.prototype._setDummyTracker = function () {
if (!this['tracker']) {
var trackers = window['_gat']['_getTrackers']();
if (trackers.length > 0) {
this['tracker'] = trackers[0];
}
}
};
/**
* Returns true if the element is found in the Array, false otherwise.
*
* @param {Array} obj Array to search at.
* @param {object} item Item to search form.
* @return {boolean} true if contains.
*/
GasHelper.prototype.inArray = function (obj, item) {
if (obj && obj.length) {
for (var i = 0; i < obj.length; i++) {
if (obj[i] === item) {
return true;
}
}
}
return false;
};
/**
* Removes special characters and Lowercase String
*
* @param {string} str to be sanitized.
* @param {boolean} strict_opt If we should remove any non ascii char.
* @return {string} Sanitized string.
*/
GasHelper.prototype._sanitizeString = function (str, strict_opt) {
str = str.toLowerCase()
.replace(/^\ +/, '')
.replace(/\ +$/, '')
.replace(/\s+/g, '_')
.replace(/[áà âãåäæª]/g, 'a')
.replace(/[éèêëЄ€]/g, 'e')
.replace(/[Ãìîï]/g, 'i')
.replace(/[óòôõöøº]/g, 'o')
.replace(/[úùûü]/g, 'u')
.replace(/[碩]/g, 'c');
if (strict_opt) {
str = str.replace(/[^a-z0-9_-]/g, '_');
}
return str.replace(/_+/g, '_');
};
/**
* Cross Browser helper to addEventListener.
*
* ga_next.js currently have a _addEventListener directive. So _gas will
* allways prefer that if available, and will use this one only as a fallback
*
* @param {HTMLElement} obj The Element to attach event to.
* @param {string} evt The event that will trigger the binded function.
* @param {function(event)} ofnc The function to bind to the element.
* @param {boolean} bubble true if event should be fired at bubble phase.
* Defaults to false. Works only on W3C compliant browser. MSFT don't support
* it.
* @return {boolean} true if it was successfuly binded.
*/
GasHelper.prototype._addEventListener = function (obj, evt, ofnc, bubble) {
var fnc = function (event) {
if (!event || !event.target) {
event = window.event;
event.target = event.srcElement;
}
return ofnc.call(obj, event);
};
// W3C model
if (obj.addEventListener) {
obj.addEventListener(evt, fnc, !!bubble);
return true;
}
// M$ft model
else if (obj.attachEvent) {
return obj.attachEvent('on' + evt, fnc);
}
// Browser doesn't support W3C or M$ft model. Time to go old school
else {
evt = 'on' + evt;
if (typeof obj[evt] === 'function') {
// Object already has a function on traditional
// Let's wrap it with our own function inside another function
fnc = (function (f1, f2) {
return function () {
f1.apply(this, arguments);
f2.apply(this, arguments);
};
}(obj[evt], fnc));
}
obj[evt] = fnc;
return true;
}
};
/**
* Cross Browser Helper to emulate jQuery.live
*
* Binds to the document root. Listens to all events of the specific type.
* If event don't bubble it won't catch
*/
GasHelper.prototype._liveEvent = function (tag, evt, ofunc) {
var gh = this;
tag = tag.toUpperCase();
tag = tag.split(',');
gh._addEventListener(document, evt, function (me) {
for (var el = me.target; el.nodeName !== 'HTML';
el = el.parentNode)
{
if (gh.inArray(tag, el.nodeName) || el.parentNode === null) {
break;
}
}
if (el && gh.inArray(tag, el.nodeName)) {
ofunc.call(el, me);
}
}, true);
};
/**
* Cross Browser DomReady function.
*
* Inspired by: http://dean.edwards.name/weblog/2006/06/again/#comment367184
*
* @param {function(Event)} callback DOMReady callback.
* @return {boolean} Ignore return value.
*/
GasHelper.prototype._DOMReady = function (callback) {
var scp = this;
function cb() {
if (cb.done) return;
cb.done = true;
callback.apply(scp, arguments);
}
if (/^(interactive|complete)/.test(document.readyState)) return cb();
this._addEventListener(document, 'DOMContentLoaded', cb, false);
this._addEventListener(window, 'load', cb, false);
};
/**
* GAS - Google Analytics on Steroids
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the MIT license.
*
* @author Eduardo Cereto <[email protected]>
*/
/**
* Google Analytics original _gaq.
*
* This never tries to do something that is not supposed to. So it won't break
* in the future.
*/
window['_gaq'] = window['_gaq'] || [];
var _prev_gas = window['_gas'] || [];
// Avoid duplicate definition
if (_prev_gas._accounts_length >= 0) {
return;
}
//Shortcuts, these speed up and compress the code
var document = window.document,
toString = Object.prototype.toString,
hasOwn = Object.prototype.hasOwnProperty,
push = Array.prototype.push,
slice = Array.prototype.slice,
trim = String.prototype.trim,
sindexOf = String.prototype.indexOf,
url = document.location.href,
documentElement = document.documentElement;
/**
* GAS Sigleton
* @constructor
*/
function GAS() {
var self = this;
self['version'] = '1.10.1';
self._accounts = {};
self._accounts_length = 0;
self._queue = _prev_gas;
self._default_tracker = '_gas1';
self.gh = {};
self._hooks = {
'_addHook': [self._addHook]
};
// Need to be pushed to make sure tracker is done
// Sets up helpers, very first thing pushed into gas
self.push(function () {
self.gh = new GasHelper();
});
}
/**
* First standard Hook that is responsible to add next Hooks
*
* _addHook calls always reurn false so they don't get pushed to _gaq
* @param {string} fn The function you wish to add a Hook to.
* @param {function()} cb The callback function to be appended to hooks.
* @return {boolean} Always false.
*/
GAS.prototype._addHook = function (fn, cb) {
if (typeof fn === 'string' && typeof cb === 'function') {
if (typeof _gas._hooks[fn] === 'undefined') {
_gas._hooks[fn] = [];
}
_gas._hooks[fn].push(cb);
}
return false;
};
/**
* Construct the correct account name to be used on _gaq calls.
*
* The account name for the first unamed account pushed to _gas is the standard
* account name. It's pushed without the account name to _gaq, so if someone
* calls directly _gaq it works as expected.
* @param {string} acct Account name.
* @return {string} Correct account name to be used already with trailling dot.
*/
function _build_acct_name(acct) {
return acct === _gas._default_tracker ? '' : acct + '.';
}
function _gaq_push(arr) {
if (_gas.debug_mode) {
try {
console.log(arr);
}catch (e) {}
}
return window['_gaq'].push(arr);
}
/**
* Everything pushed to _gas is executed by this call.
*
* This function should not be called directly. Instead use _gas.push
* @return {number} This is the same return as _gaq.push calls.
*/
GAS.prototype._execute = function () {
var args = slice.call(arguments),
self = this,
sub = args.shift(),
gaq_execute = true,
i, foo, hooks, acct_name, repl_sub, return_val = 0;
if (typeof sub === 'function') {
// Pushed functions are executed right away
return _gaq_push(
(function (s, gh) {
return function () {
// pushed functions receive helpers through this object
s.call(gh);
};
}(sub, self.gh))
);
} else if (typeof sub === 'object' && sub.length > 0) {
foo = sub.shift();
if (sindexOf.call(foo, '.') >= 0) {
acct_name = foo.split('.')[0];
foo = foo.split('.')[1];
} else {
acct_name = undefined;
}
// Execute hooks
hooks = self._hooks[foo];
if (hooks && hooks.length > 0) {
for (i = 0; i < hooks.length; i++) {
try {
repl_sub = hooks[i].apply(self.gh, sub);
if (repl_sub === false) {
// Returning false from a hook cancel the call
gaq_execute = false;
} else {
if (repl_sub && repl_sub.length > 0) {
// Returning an array changes the call parameters
sub = repl_sub;
}
}
} catch (e) {
if (foo !== '_trackException') {
self.push(['_trackException', e]);
}
}
}
}
// Cancel execution on _gaq if any hook returned false
if (gaq_execute === false) {
return 1;
}
// Intercept _setAccount calls
if (foo === '_setAccount') {
for (i in self._accounts) {
if (self._accounts[i] === sub[0]) {
// Repeated account
if (acct_name === undefined) {
return 1;
}
}
}
acct_name = acct_name || '_gas' +
String(self._accounts_length + 1);
// Force that the first unamed account is _gas1
if (typeof self._accounts['_gas1'] === 'undefined' &&
sindexOf.call(acct_name, '_gas') !== -1) {
acct_name = '_gas1';
}
self._accounts[acct_name] = sub[0];
self._accounts_length += 1;
acct_name = _build_acct_name(acct_name);
return_val = _gaq_push([acct_name + foo, sub[0]]);
// Must try t get the tracker if it's a _setAccount
self.gh._setDummyTracker();
return return_val;
}
// Intercept functions that can only be called once.
if (foo === '_link' || foo === '_linkByPost' || foo === '_require' ||
foo === '_anonymizeIp')
{
args = slice.call(sub);
args.unshift(foo);
return _gaq_push(args);
}
// If user provides account than trigger event for just that account.
var acc_foo;
if (acct_name && self._accounts[acct_name]) {
acc_foo = _build_acct_name(acct_name) + foo;
args = slice.call(sub);
args.unshift(acc_foo);
return _gaq_push(args);
}
// Call Original _gaq, for all accounts
if (self._accounts_length > 0) {
for (i in self._accounts) {
if (hasOwn.call(self._accounts, i)) {
acc_foo = _build_acct_name(i) + foo;
args = slice.call(sub);
args.unshift(acc_foo);
return_val += _gaq_push(args);
}
}
} else {
// If there are no accounts we just push it to _gaq
args = slice.call(sub);
args.unshift(foo);
return _gaq_push(args);
}
return return_val ? 1 : 0;
}
};
/**
* Standard method to execute GA commands.
*
* Everything pushed to _gas is in fact pushed back to _gaq. So Helpers are
* ready for hooks. This creates _gaq as a series of functions that call
* _gas._execute() with the same arguments.
*/
GAS.prototype.push = function () {
var self = this;
var args = slice.call(arguments);
for (var i = 0; i < args.length; i++) {
(function (arr, self) {
window['_gaq'].push(function () {
self._execute.call(self, arr);
});
}(args[i], self));
}
};
/**
* _gas main object.
*
* It's supposed to be used just like _gaq but here we extend it. In it's core
* everything pushed to _gas is run through possible hooks and then pushed to
* _gaq
*/
window['_gas'] = _gas = new GAS();
/**
* Hook for _trackException
*
* Watchout for circular calls
*/
_gas.push(['_addHook', '_trackException', function (exception, message) {
_gas.push(['_trackEvent',
'Exception ' + (exception.name || 'Error'),
message || exception.message || exception,
url
]);
return false;
}]);
/**
* Hook to enable Debug Mode
*/
_gas.push(['_addHook', '_setDebug', function (set_debug) {
_gas.debug_mode = !!set_debug;
}]);
/**
* Hook to Remove other Hooks
*
* It will remove the last inserted hook from a _gas function.
*
* @param {string} func _gas Function Name to remove Hooks from.
* @return {boolean} Always returns false.
*/
_gas.push(['_addHook', '_popHook', function (func) {
var arr = _gas._hooks[func];
if (arr && arr.pop) {
arr.pop();
}
return false;
}]);
/**
* Hook to set the default tracker.
*
* The default tracker is the nameless tracker that is pushed into _gaq_push
*/
_gas.push(['_addHook', '_gasSetDefaultTracker', function (tname) {
_gas._default_tracker = tname;
return false;
}]);
/**
* This is kept just for backward compatibility since it's now supported
* natively in _gaq.
*/
_gas.push(['_addHook', '_trackPageview', function () {
var args = slice.call(arguments);
if (args.length >= 2 &&
typeof args[0] === 'string' && typeof args[1] === 'string')
{
return [{
'page': args[0],
'title': args[1]
}];
}
return args;
}]);
/**
* GAS - Google Analytics on Steroids
*
* Download Tracking Plugin
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <[email protected]>
*/
/**
* Extracts the file extension and check it against a list
*
* Will extract the extensions from a url and check if it matches one of
* possible options. Used to verify if a url corresponds to a download link.
*
* @this {GasHelper} GA Helper object.
* @param {string} src The url to check.
* @param {Array} extensions an Array with strings containing the possible
* extensions.
* @return {boolean|string} the file extension or false.
*/
function _checkFile(src, extensions) {
if (typeof src !== 'string') {
return false;
}
var ext = src.split('?')[0];
ext = ext.split('.');
ext = ext[ext.length - 1];
if (ext && this.inArray(extensions, ext)) {
return ext;
}
return false;
}
/**
* Register the event to listen to downloads
*
* @this {GasHelper} GA Helper object.
* @param {Array|object} opts List of possible extensions for download
* links.
*/
var _trackDownloads = function (opts) {
var gh = this;
if (!gh._downloadTracked) {
gh._downloadTracked = true;
} else {
//Oops double tracking detected.
return;
}
if (!opts) {
opts = {'extensions': []};
} else if (typeof opts === 'string') {
// support legacy opts as String of extensions
opts = {'extensions': opts.split(',')};
} else if (opts.length >= 1) {
// support legacy opts Array of extensions
opts = {'extensions': opts};
}
opts['category'] = opts['category'] || 'Download';
var ext = 'xls,xlsx,doc,docx,ppt,pptx,pdf,txt,zip';
ext += ',rar,7z,exe,wma,mov,avi,wmv,mp3,csv,tsv';
ext = ext.split(',');
opts['extensions'] = opts['extensions'].concat(ext);
gh._liveEvent('a', 'mousedown', function (e) {
var el = this;
if (el.href) {
var ext = _checkFile.call(gh,
el.href, opts['extensions']
);
if (ext) {
_gas.push(['_trackEvent',
opts['category'], ext, el.href
]);
}
}
});
return false;
};
/**
* GAA Hook, receive the extensions to extend default extensions. And trigger
* the binding of the events.
*
* @param {string|Array|object} opts GAs Options. Also backward compatible
* with array or string of extensions.
*/
_gas.push(['_addHook', '_gasTrackDownloads', _trackDownloads]);
// Old API to be deprecated on v2.0
_gas.push(['_addHook', '_trackDownloads', _trackDownloads]);
/**
* GAS - Google Analytics on Steroids
*
* Ecommerce Meta
*
* Copyright 2012, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <[email protected]>
*/
function _gasMetaEcommerce() {
var i, meta,
f_trans = 0,
f_item = 0,
metas = document.getElementsByTagName('meta');
for (i = 0; i < metas.length; i++) {
if (metas[i].name === 'ga_trans') {
// Fire transaction
meta = metas[i].content.split('^');
if (meta.length < 3) {
// 3 is the minimum for transaction
break;
}
// Add default values for remaining params
while (meta.length < 8) {
meta.push('');
}
_gas.push(['_addTrans',
meta[0],
meta[1],
meta[2],
meta[3],
meta[4],
meta[5],
meta[6],
meta[7]
]);
f_trans++;
}
else if (metas[i].name === 'ga_item') {
// Fire item
meta = metas[i].content.split('^');
if (meta.length === 6) {
_gas.push(['_addItem',
meta[0],
meta[1],
meta[2],
meta[3],
meta[4],
meta[5]
]);
f_item++;
}
}
}
if (f_trans > 0 && f_item > 0) {
_gas.push(['_trackTrans']);
//_gas.push(['_clearTrans']);
}
}
_gas.push(['_addHook', '_gasMetaEcommerce', _gasMetaEcommerce]);
/**
* Hook to sanity check trackEvents
*
* The value is rounded and parsed to integer.
* Negative values are sent as zero.
* If val is NaN than it is sent as zero.
*/
_gas.push(['_addHook', '_trackEvent', function () {
var args = slice.call(arguments);
if (args[3]) {
args[3] = (args[3] < 0 ? 0 : Math.round(args[3])) || 0;
}
return args;
}]);
/**
* GAS - Google Analytics on Steroids
*
* Form Tracking Plugin
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <[email protected]>
*/
/**
* get the form name for a specific elemet
*
* @param {DOMElemet} el Dom Element.
* @return {String} Form Name or Id.
*/
function getFormName(el) {
while (el && el.nodeName !== 'HTML') {
if (el.nodeName === 'FORM') {break; }
el = el.parentNode;
}
if (el.nodeName === 'FORM') {
return el.name || el.id || 'none';
}
return 'none';
}
var _gasTrackForms = function (opts) {
if (!this._formTracked) {
this._formTracked = true;
} else {
//Oops double tracking detected.
return;
}
var scp = this;
if (typeof opts !== 'object') {
opts = {};
}
// Make sure required attrs are defined or fallback to default
opts['category'] = opts['category'] || 'Form Tracking';
//opts['live'] = opts['live'] || true; //Ignored
var trackField = function (e) {
var el = e.target,
el_name = el.name || el.id || el.type || el.nodeName,
form_name = getFormName(el),
action = 'form (' + form_name + ')',
label = el_name + ' (' + e.type + ')';
_gas.push(['_trackEvent', opts['category'], action, label]);
};
scp._DOMReady(function () {
var changeTags = ['input', 'select', 'textarea', 'hidden'];
var submitTags = ['form'];
var elements = [];
var i, j;
for (i = 0; i < changeTags.length; i++) {
elements = document.getElementsByTagName(changeTags[i]);
for (j = 0; j < elements.length; j++) {
scp._addEventListener(elements[j], 'change', trackField);
}
}
for (i = 0; i < submitTags.length; i++) {
elements = document.getElementsByTagName(submitTags[i]);
for (j = 0; j < elements.length; j++) {
scp._addEventListener(elements[j], 'submit', trackField);
}
}
});
};
_gas.push(['_addHook', '_gasTrackForms', _gasTrackForms]);
// Old API to be deprecated on v2.0
_gas.push(['_addHook', '_trackForms', _gasTrackForms]);
/**
* GAS - Google Analytics on Steroids
*
* HTML5 Video Tracking Plugin
*
* Copyright 2011, Cardinal Path
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <[email protected]>
*/
/**
* Triggers the actual video/audio GA events
*
* To be used as a callback for the HTML5 media events
*
* @param {Event} e A reference to the HTML event fired.
* @this {HTMLMediaElement} The HTML element firing the event
*/
function _trackMediaElement(e) {
_gas.push(['_trackEvent', this.tagName, e.type, this.currentSrc]);
}
/**
* Triggers the HTML5 Video Tracking on the page
* @param {String} tag Either 'audio' or 'video'.
* @this {GasHelper} GA Helper object.
*/
var _trackMedia = function (tag) {
var self = this;
self._liveEvent(tag, 'play', _trackMediaElement);
self._liveEvent(tag, 'pause', _trackMediaElement);
self._liveEvent(tag, 'ended', _trackMediaElement);
};
var _trackVideo = function () {
if (!this._videoTracked) {
this._videoTracked = true;
} else {
//Oops double tracking detected.
return;
}
_trackMedia.call(this, 'video');
};
var _trackAudio = function () {
if (!this._audioTracked) {
this._audioTracked = true;
} else {
//Oops double tracking detected.
return;
}
_trackMedia.call(this, 'audio');
};
_gas.push(['_addHook', '_gasTrackVideo', _trackVideo]);
_gas.push(['_addHook', '_gasTrackAudio', _trackAudio]);
// Old API to be deprecated on v2.0
_gas.push(['_addHook', '_trackVideo', _trackVideo]);
_gas.push(['_addHook', '_trackAudio', _trackAudio]);
/**
* GAS - Google Analytics on Steroids
*
* HTML Markup Plugin
*
* Copyright 2012, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <[email protected]>
*/
/**
* Sets Default pagename and Custom Vars based on Meta
*
* If a meta name='ga_vpv' is availalbe on the page use that as a page
* replacement if the pageview is not passed as parameter.
*
* If meta name="ga_custom_var" the 4 values for a custom var must be on
* content separated by a caret (^).
*/
function _gasMeta() {
var i, meta,
metas = document.getElementsByTagName('meta');
for (i = 0; i < metas.length; i++) {
if (metas[i].name === 'ga_vpv') {
meta = metas[i].content;
(function (vpv) {
window._gas.push(['_addHook', '_trackPageview', function (p) {
if (p === undefined) {
return [vpv];
}
}]);
}(meta));
} else if (metas[i].name === 'ga_custom_var') {
meta = metas[i].content.split('^');
if (meta.length === 4) {
window._gas.push(['_setCustomVar',
parseInt(meta[0], 10),
meta[1],
meta[2],
parseInt(meta[3], 10)
]);
}
}
}
}
/**
* Listens to all clicks and looks for a tagged element on it.
*
* Events have the following params:
* x-ga-event-category (required) – The category of the event specified in
* the solution design document
* x-ga-event-action (required) – The action of the event specified in the
* solution design document
* x-ga-event-label (optional) – The label of the event specified in the
* solution design document. If no label is specified in the solution design
* document, this attribute can be omitted
* x-ga-event-value (optional) – The value (integer) of the event specified
* in the solution design document. If no value is specified in the solution
* design document, this attribute can be omitted
* x-ga-event-noninteractive (optional) – Boolean (true/false) value
* specified in the solution design document. If the non-interactive value is
* not specified, this attribute can be omitted
*
* Social Actions have the following params:
* x-ga-social-network (required) – The network of the social interaction
* specified in the solution design document
* x-ga-social-action (required) – The action of the social interaction
* specified in the solution design document
* x-ga-social-target (optional) – The target of the social interaction
* specified in the solution design document. If no target is specified, this
* attribute can be omitted
* x-ga-social-pagepath (optional) – The page path of the social interaction
* specified in the solution design document. If no page path is specified,
* this attribute can be omitted
*/
function _gasHTMLMarkup() {
var gh = this;
gh._addEventListener(document, 'mousedown', function (me) {
var el;
for (el = me.target; el.nodeName !== 'HTML';
el = el.parentNode) {
if (el.getAttribute('x-ga-event-category')) {
// Event element clicked, fire the _trackEvent
window._gas.push(['_trackEvent',
el.getAttribute('x-ga-event-category'),
el.getAttribute('x-ga-event-action'),
el.getAttribute('x-ga-event-label') || undefined,
parseInt(el.getAttribute('x-ga-event-value'), 10) || 0,
el.getAttribute('x-ga-event-noninteractive') === 'true' ? true : false
]);
}
if (el.getAttribute('x-ga-social-network')) {
// Social Action Clicked fire _trackSocial
window._gas.push(['_trackSocial',
el.getAttribute('x-ga-social-network'),
el.getAttribute('x-ga-social-action'),
el.getAttribute('x-ga-social-target') || undefined,
el.getAttribute('x-ga-social-pagepath') || undefined
]);
}
if (el.parentNode === null) {
break;
}
}
}, true);
}
_gas.push(['_addHook', '_gasMeta', _gasMeta]);
_gas.push(['_addHook', '_gasHTMLMarkup', _gasHTMLMarkup]);
/**
* GAS - Google Analytics on Steroids
*
* MailTo tracking plugin
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*/
/**
* GAS plugin to track mailto: links
*
* @param {object} opts GAS Options.
*/
var _gasTrackMailto = function (opts) {
if (!this._mailtoTracked) {
this._mailtoTracked = true;
} else {
//Oops double tracking detected.
return;
}
if (!opts) {
opts = {};
}
opts['category'] = opts['category'] || 'Mailto';
this._liveEvent('a', 'mousedown', function (e) {
var el = e.target;
if (el && el.href && el.href.toLowerCase &&
sindexOf.call(el.href.toLowerCase(), 'mailto:') === 0) {
_gas.push(['_trackEvent', opts['category'], el.href.substr(7)]);
}
});
return false;
};
_gas.push(['_addHook', '_gasTrackMailto', _gasTrackMailto]);
// Old API to be deprecated on v2.0
_gas.push(['_addHook', '_trackMailto', _gasTrackMailto]);
/**
* GAS - Google Analytics on Steroids
*
* Max-Scroll Tracking Plugin
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <[email protected]>
*/
var _maxScrollOpts;
/**
* Get current browser viewpane heigtht
*
* @return {number} height.
*/
function _get_window_height() {
return window.innerHeight || documentElement.clientHeight ||
document.body.clientHeight || 0;
}
/**
* Get current absolute window scroll position
*
* @return {number} YScroll.
*/
function _get_window_Yscroll() {
return window.pageYOffset || document.body.scrollTop ||
documentElement.scrollTop || 0;
}
/**
* Get current absolute document height
*