This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 735
/
analytics.js
1924 lines (1470 loc) · 61.2 KB
/
analytics.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
// Analytics.js 0.4.4
// (c) 2013 Segment.io Inc.
// Analytics.js may be freely distributed under the MIT license.
(function () {
// Setup
// -----
// The `analytics` object that will be exposed to you on the global object.
var analytics = {
// Cache the `userId` when a user is identified.
userId : null,
// Store the date when the page loaded, for services that depend on it.
date : new Date(),
// Store window.onload state so that analytics that rely on it can be loaded
// even after onload fires.
loaded : false,
// Whether analytics.js has been initialized with providers.
initialized : false,
// The amount of milliseconds to wait for requests to providers to clear
// before navigating away from the current page.
timeout : 250,
// Providers
// ---------
// A dictionary of analytics providers that _can_ be initialized.
initializableProviders : {},
// An array of analytics providers that are initialized.
providers : [],
// Adds a provider to the list of available providers that can be
// initialized.
addProvider : function (name, provider) {
this.initializableProviders[name] = provider;
},
// Initialize
// ----------
// Call **initialize** to setup analytics.js before identifying or
// tracking any users or events. Here's what a call to **initialize**
// might look like:
//
// analytics.initialize({
// 'Google Analytics' : 'UA-XXXXXXX-X',
// 'Segment.io' : 'XXXXXXXXXXX',
// 'KISSmetrics' : 'XXXXXXXXXXX'
// });
//
// * `providers` is a dictionary of the providers you want to enabled.
// The keys are the names of the providers and their values are either
// an api key, or dictionary of extra settings (including the api key).
initialize : function (providers) {
// Reset our state.
this.providers = [];
this.userId = null;
// Initialize each provider with the proper settings, and copy the
// provider into `this.providers`.
for (var key in providers) {
var provider = this.initializableProviders[key];
var settings = providers[key];
if (!provider) throw new Error('Could not find a provider named "'+key+'"');
provider.initialize(settings);
this.providers.push(provider);
}
// Update the initialized state that other methods rely on.
this.initialized = true;
// Try to use id and event parameters from the url
var userId = this.utils.getUrlParameter(window.location.search, 'ajs_uid');
if (userId) this.identify(userId);
var event = this.utils.getUrlParameter(window.location.search, 'ajs_event');
if (event) this.track(event);
},
// Identify
// --------
// Identifying a user ties all of their actions to an ID you recognize
// and records properties about a user. An example identify:
//
// analytics.identify('4d3ed089fb60ab534684b7e0', {
// name : 'Achilles',
// email : 'achilles@segment.io',
// age : 23
// });
//
// * `userId` (optional) is the ID you know the user by. Ideally this
// isn't an email, because the user might be able to change their email
// and you don't want that to affect your analytics.
//
// * `traits` (optional) is a dictionary of traits to tie your user.
// Things like `name`, `age` or `friendCount`. If you have them, you
// should always store a `name` and `email`.
//
// * `callback` (optional) is a function to call after the a small
// timeout to give the identify requests a chance to be sent.
identify : function (userId, traits, callback) {
if (!this.initialized) return;
// Allow for not passing traits, but passing a callback.
if (this.utils.isFunction(traits)) {
callback = traits;
traits = null;
}
// Allow for identifying traits without setting a `userId`, for
// anonymous users whose traits you learn.
if (this.utils.isObject(userId)) {
if (traits && this.utils.isFunction(traits)) callback = traits;
traits = userId;
userId = null;
}
// Cache the `userId`, or use saved one.
if (userId !== null)
this.userId = userId;
else
userId = this.userId;
// Call `identify` on all of our enabled providers that support it.
for (var i = 0, provider; provider = this.providers[i]; i++) {
if (!provider.identify) continue;
provider.identify(userId, this.utils.clone(traits));
}
if (callback && this.utils.isFunction(callback)) {
setTimeout(callback, this.timeout);
}
},
// Track
// -----
// Whenever a visitor triggers an event on your site that you're
// interested in, you'll want to track it. An example track:
//
// analytics.track('Added a Friend', {
// level : 'hard',
// volume : 11
// });
//
// * `event` is the name of the event. The best names are human-readable
// so that your whole team knows what they mean when they analyze your
// data.
//
// * `properties` (optional) is a dictionary of properties of the event.
// Property keys are all camelCase (we'll alias to non-camelCase for
// you automatically for providers that require it).
//
// * `callback` (optional) is a function to call after the a small
// timeout to give the track requests a chance to be sent.
track : function (event, properties, callback) {
if (!this.initialized) return;
// Allow for not passing properties, but passing a callback.
if (this.utils.isFunction(properties)) {
callback = properties;
properties = null;
}
// Call `track` on all of our enabled providers that support it.
for (var i = 0, provider; provider = this.providers[i]; i++) {
if (!provider.track) continue;
provider.track(event, this.utils.clone(properties));
}
if (callback && this.utils.isFunction(callback)) {
setTimeout(callback, this.timeout);
}
},
// ### trackLink
// A helper for tracking outbound links that would normally leave the
// page before the track calls went out. It works by wrapping the calls
// in as short of a timeout as possible to fire the track call, because
// [response times matter](http://theixdlibrary.com/pdf/Miller1968.pdf).
//
// * `link` is either a single link DOM element, or an array of link
// elements like jQuery gives you.
//
// * `event` and `properties` are passed directly to `analytics.track`
// and take the same options. `properties` can also be a function that
// will get passed the link that was clicked, and should return a
// dictionary of event properties.
trackLink : function (link, event, properties) {
if (!link) return;
// Turn a single link into an array so that we're always handling
// arrays, which allows for passing jQuery objects.
if (this.utils.isElement(link)) link = [link];
// Bind to all the links in the array.
for (var i = 0; i < link.length; i++) {
var self = this;
var el = link[i];
this.utils.bind(el, 'click', function (e) {
// Allow for properties to be a function. And pass it the
// link element that was clicked.
if (self.utils.isFunction(properties)) properties = properties(el);
// Fire a normal track call.
self.track(event, properties);
// To justify us preventing the default behavior we must:
//
// * Have an `href` to use.
// * Not have a `target="_blank"` attribute.
// * Not have any special keys pressed, because they might
// be trying to open in a new tab, or window, or download
// the asset.
//
// This might not cover all cases, but we'd rather throw out
// an event than miss a case that breaks the experience.
if (el.href && el.target !== '_blank' && !self.utils.isMeta(e)) {
// Prevent the link's default redirect in all the sane
// browsers, and also IE.
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
// Navigate to the url after a small timeout, giving the
// providers time to track the event.
setTimeout(function () {
window.location.href = el.href;
}, self.timeout);
}
});
}
},
// ### trackForm
// Similar to `trackClick`, this is a helper for tracking form
// submissions that would normally leave the page before a track call
// can be sent. It works by preventing the default submit, sending a
// track call, and then submitting the form programmatically.
//
// * `form` is either a single form DOM element, or an array of
// form elements like jQuery gives you.
//
// * `event` and `properties` are passed directly to `analytics.track`
// and take the same options. `properties` can also be a function that
// will get passed the form that was submitted, and should return a
// dictionary of event properties.
trackForm : function (form, event, properties) {
if (!form) return;
// Turn a single element into an array so that we're always handling
// arrays, which allows for passing jQuery objects.
if (this.utils.isElement(form)) form = [form];
// Bind to all the forms in the array.
for (var i = 0; i < form.length; i++) {
var self = this;
var el = form[i];
this.utils.bind(el, 'submit', function (e) {
// Allow for properties to be a function. And pass it the
// form element that was submitted.
if (self.utils.isFunction(properties)) properties = properties(el);
// Fire a normal track call.
self.track(event, properties);
// Prevent the form's default submit in all the sane
// browsers, and also IE.
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
// Submit the form after a small timeout, giving the event
// time to get fired.
setTimeout(function () {
el.submit();
}, this.timeout);
});
}
},
// Pageview
// --------
// For single-page applications where real page loads don't happen, the
// **pageview** method simulates a page loading event for all providers
// that track pageviews and support it. This is the equivalent of
// calling `_gaq.push(['trackPageview'])` in Google Analytics.
//
// **pageview** is _not_ for sending events about which pages in your
// app the user has loaded. For that, use a regular track call like:
// `analytics.track('View Signup Page')`. Or, if you think you've come
// up with a badass abstraction, submit a pull request!
//
// * `url` (optional) is the url path that you want to be associated
// with the page. You only need to pass this argument if the URL hasn't
// changed but you want to register a new pageview.
pageview : function (url) {
if (!this.initialized) return;
// Call `pageview` on all of our enabled providers that support it.
for (var i = 0, provider; provider = this.providers[i]; i++) {
if (!provider.pageview) continue;
provider.pageview(url);
}
},
// Utils
// -----
utils : {
// Attach an event handler to a DOM element, even in IE.
bind : function (el, event, callback) {
if (el.addEventListener) {
el.addEventListener(event, callback, false);
} else if (el.attachEvent) {
el.attachEvent('on' + event, callback);
}
},
// Given a DOM event, tell us whether a meta key or button was
// pressed that would make a link open in a new tab, window,
// start a download, or anything else that wouldn't take the user to
// a new page.
isMeta : function (e) {
if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return true;
// Logic that handles checks for the middle mouse button, based
// on [jQuery](https://github.com/jquery/jquery/blob/master/src/event.js#L466).
var which = e.which, button = e.button;
if (!which && button !== undefined) {
return (!button & 1) && (!button & 2) && (button & 4);
} else if (which === 2) {
return true;
}
return false;
},
// Given a timestamp, return its value in seconds. For providers
// that rely on Unix time instead of millis.
getSeconds : function (time) {
return Math.floor((new Date(time)) / 1000);
},
// A helper to extend objects with properties from other objects.
// Based off of the [underscore](https://github.com/documentcloud/underscore/blob/master/underscore.js#L763)
// method.
extend : function (obj) {
var args = Array.prototype.slice.call(arguments, 1);
for (var i = 0, source; source = args[i]; i++) {
for (var property in source) {
obj[property] = source[property];
}
}
return obj;
},
// A helper to shallow-ly clone objects, so that they don't get
// mangled by different analytics providers because of the
// reference.
clone : function (obj) {
if (!obj) return;
return this.extend({}, obj);
},
// A helper to alias certain object's keys to different key names.
// Useful for abstracting over providers that require specific key
// names.
alias : function (obj, aliases) {
for (var prop in aliases) {
var alias = aliases[prop];
if (obj[prop] !== undefined) {
obj[alias] = obj[prop];
delete obj[prop];
}
}
},
// Type detection helpers, copied from
// [underscore](https://github.com/documentcloud/underscore/blob/master/underscore.js#L926-L946).
isElement : function(obj) {
return !!(obj && obj.nodeType === 1);
},
isArray : Array.isArray || function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
},
isObject : function (obj) {
return obj === Object(obj);
},
isString : function (obj) {
return Object.prototype.toString.call(obj) === '[object String]';
},
isFunction : function (obj) {
return Object.prototype.toString.call(obj) === '[object Function]';
},
isNumber : function (obj) {
return Object.prototype.toString.call(obj) === '[object Number]';
},
// Email detection helper to loosely validate emails.
isEmail : function (string) {
return (/.+\@.+\..+/).test(string);
},
// A helper to resolve a settings object. It allows for `settings`
// to be a string in the case of using the shorthand where just an
// api key is passed. `fieldName` is what the provider calls their
// api key.
resolveSettings : function (settings, fieldName) {
if (!this.isString(settings) && !this.isObject(settings))
throw new Error('Could not resolve settings.');
if (!fieldName)
throw new Error('You must provide an api key field name.');
// Allow for settings to just be an API key, for example:
//
// { 'Google Analytics : 'UA-XXXXXXX-X' }
if (this.isString(settings)) {
var apiKey = settings;
settings = {};
settings[fieldName] = apiKey;
}
return settings;
},
// A helper to track events based on the 'anjs' url parameter
getUrlParameter : function (urlSearchParameter, paramKey) {
var params = urlSearchParameter.replace('?', '').split('&');
for (var i = 0; i < params.length; i += 1) {
var param = params[i].split('=');
if (param.length === 2 && param[0] === paramKey) {
return decodeURIComponent(param[1]);
}
}
},
// Takes a url and parses out all of the pieces of it. Pulled from
// [Component's url module](https://github.com/component/url).
parseUrl : function (url) {
var a = document.createElement('a');
a.href = url;
return {
href : a.href,
host : a.host || location.host,
port : a.port || location.port,
hash : a.hash,
hostname : a.hostname || location.hostname,
pathname : a.pathname,
protocol : !a.protocol || ':' === a.protocol ? location.protocol : a.protocol,
search : a.search,
query : a.search.slice(1)
};
}
}
};
// Add `trackClick` and `trackSubmit` for backwards compatibility.
analytics.trackClick = analytics.trackLink;
analytics.trackSubmit = analytics.trackForm;
// Wrap any existing `onload` function with our own that will cache the
// loaded state of the page.
var oldonload = window.onload;
window.onload = function () {
analytics.loaded = true;
if (analytics.utils.isFunction(oldonload)) oldonload();
};
window.analytics = analytics;
})();
// Bitdeli
// -------
// * [Documentation](https://bitdeli.com/docs)
// * [JavaScript API Reference](https://bitdeli.com/docs/javascript-api.html)
analytics.addProvider('Bitdeli', {
settings : {
inputId : null,
authToken : null,
// Whether or not to track an initial pageview when the page first
// loads. You might not want this if you're using a single-page app.
initialPageview : true
},
// Initialize
// ----------
// Changes to the Bitdeli snippet:
//
// * Use `window._bdq` instead of `_bdq` to access existing queue instance
// * Always load the latest version of the library
// (major backwards incompatible updates will use another URL)
initialize : function (settings) {
var utils = analytics.utils;
if (!utils.isObject(settings) ||
!utils.isString(settings.inputId) ||
!utils.isString(settings.authToken)) {
throw new Error("Settings must be an object with properties 'inputId' and 'authToken'.");
}
utils.extend(this.settings, settings);
var _bdq = window._bdq = window._bdq || [];
_bdq.push(["setAccount", this.settings.inputId, this.settings.authToken]);
if (this.settings.initialPageview) _bdq.push(["trackPageview"]);
(function() {
var bd = document.createElement("script"); bd.type = "text/javascript"; bd.async = true;
bd.src = ("https:" == document.location.protocol ? "https://" : "http://") + "d2flrkr957qc5j.cloudfront.net/bitdeli.min.js";
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bd, s);
})();
},
// Identify
// --------
// Bitdeli uses two separate methods: `identify` for storing the `userId`
// and `set` for storing `traits`.
identify : function (userId, traits) {
if (userId) window._bdq.push(['identify', userId]);
if (traits) window._bdq.push(['set', traits]);
},
// Track
// -----
track : function (event, properties) {
window._bdq.push(['track', event, properties]);
},
// Pageview
// --------
pageview : function (url) {
// If `url` is undefined, Bitdeli uses the current page URL instead.
window._bdq.push(['trackPageview', url]);
}
});
// Chartbeat
// ---------
// [Documentation](http://chartbeat.com/docs/adding_the_code/),
// [documentation](http://chartbeat.com/docs/configuration_variables/),
// [documentation](http://chartbeat.com/docs/handling_virtual_page_changes/).
analytics.addProvider('Chartbeat', {
settings : {
domain : null,
uid : null
},
// Initialize
// ----------
// Changes to the Chartbeat snippet:
//
// * Pass `settings` directly as the config object.
// * Replaced the date with our stored `date` variable.
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'uid');
analytics.utils.extend(this.settings, settings);
// Since all the custom settings just get passed through, update the
// Chartbeat `_sf_async_config` variable with settings.
window._sf_async_config = this.settings || {};
(function(){
// Use the stored date from when we were loaded.
window._sf_endpt = analytics.date.getTime();
var e = document.createElement('script');
e.setAttribute('language', 'javascript');
e.setAttribute('type', 'text/javascript');
e.setAttribute('src',
(('https:' == document.location.protocol) ?
'https://a248.e.akamai.net/chartbeat.download.akamai.com/102508/' :
'http://static.chartbeat.com/') +
'js/chartbeat.js');
document.body.appendChild(e);
})();
},
// Pageview
// --------
pageview : function (url) {
window.pSUPERFLY.virtualPage(url || window.location.pathname);
}
});
// Clicky
// ------
// [Documentation](http://clicky.com/help/customization/manual?new-domain).
analytics.addProvider('Clicky', {
settings : {
siteId : null
},
// Initialize
// ----------
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'siteId');
analytics.utils.extend(this.settings, settings);
var clicky_site_ids = window.clicky_site_ids = window.clicky_site_ids || [];
clicky_site_ids.push(settings.siteId);
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
var protocol = ('https:' == document.location.protocol) ? 'https:' : 'http:';
s.src = protocol + '//static.getclicky.com/js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);
})();
},
// Track
// -----
track : function (event, properties) {
// We aren't guaranteed `clicky` is available until the script has been
// requested and run, hence the check.
if (window.clicky) window.clicky.log(window.location.href, event);
}
});
// comScore
// ---------
// [Documentation](http://direct.comscore.com/clients/help/FAQ.aspx#faqTagging)
analytics.addProvider('comScore', {
settings : {
c1 : '2',
c2 : null
},
// Initialize
// ----------
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'c2');
analytics.utils.extend(this.settings, settings);
var _comscore = window._comscore = window._comscore || [];
_comscore.push(this.settings);
(function() {
var s = document.createElement('script');
var el = document.getElementsByTagName('script')[0];
s.async = true;
s.src = (document.location.protocol == 'https:' ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js';
el.parentNode.insertBefore(s, el);
})();
// NOTE: the <noscript><img> bit in the docs is ignored
// because we have to run JS in order to do any of this!
}
});
// CrazyEgg
// --------
// [Documentation](www.crazyegg.com).
analytics.addProvider('CrazyEgg', {
settings : {
apiKey : null
},
// Initialize
// ----------
// Changes to the CrazyEgg snippet:
//
// * Concatenate `apiKey` into the URL.
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'apiKey');
analytics.utils.extend(this.settings, settings);
var apiKey = this.settings.apiKey;
(function(){
var a = document.createElement('script');
var b = document.getElementsByTagName('script')[0];
var protocol = ('https:' == document.location.protocol) ? 'https:' : 'http:';
a.src = protocol+'//dnn506yrbagrg.cloudfront.net/pages/scripts/'+apiKey+'.js?'+Math.floor(new Date().getTime()/3600000);
a.async = true;
a.type = 'text/javascript';
b.parentNode.insertBefore(a,b);
})();
}
});
// Customer.io
// -----------
// [Documentation](http://customer.io/docs/api/javascript.html).
analytics.addProvider('Customer.io', {
settings : {
siteId : null
},
// Initialize
// ----------
// Changes to the Chartbeat snippet:
//
// * Add `siteId`.
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'siteId');
analytics.utils.extend(this.settings, settings);
var self = this;
var _cio = window._cio = window._cio || [];
(function() {
var a,b,c;
a = function (f) {
return function () {
_cio.push([f].concat(Array.prototype.slice.call(arguments,0)));
};
};
b = ['identify', 'track'];
for (c = 0; c < b.length; c++) {
_cio[b[c]] = a(b[c]);
}
var t = document.createElement('script'),
s = document.getElementsByTagName('script')[0];
t.async = true;
t.id = 'cio-tracker';
t.setAttribute('data-site-id', self.settings.siteId);
t.src = 'https://assets.customer.io/assets/track.js';
s.parentNode.insertBefore(t, s);
})();
},
// Identify
// --------
identify : function (userId, traits) {
// Don't do anything if we just have traits, because Customer.io
// requires a `userId`.
if (!userId) return;
traits || (traits = {});
// Customer.io takes the `userId` as part of the traits object.
traits.id = userId;
// If there wasn't already an email and the userId is one, use it.
if (!traits.email && analytics.utils.isEmail(userId)) {
traits.email = userId;
}
// Swap the `created` trait to the `created_at` that Customer.io needs
// (in seconds).
if (traits.created) {
traits.created_at = analytics.utils.getSeconds(traits.created);
delete traits.created;
}
window._cio.identify(traits);
},
// Track
// -----
track : function (event, properties) {
window._cio.track(event, properties);
}
});
// Errorception
// ------------
// [Documentation](http://errorception.com/).
analytics.addProvider('Errorception', {
settings : {
projectId : null,
// Whether to store metadata about the user on `identify` calls, using
// the [Errorception `meta` API](http://blog.errorception.com/2012/11/capture-custom-data-with-your-errors.html).
meta : true
},
// Initialize
// ----------
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'projectId');
analytics.utils.extend(this.settings, settings);
var _errs = window._errs = window._errs || [settings.projectId];
(function(a,b){
a.onerror = function () {
_errs.push(arguments);
};
var d = function () {
var a = b.createElement('script'),
c = b.getElementsByTagName('script')[0],
protocol = ('https:' == document.location.protocol) ? 'https:' : 'http:';
a.src = protocol + '//d15qhc0lu1ghnk.cloudfront.net/beacon.js';
a.async = true;
c.parentNode.insertBefore(a,c);
};
a.addEventListener ? a.addEventListener('load', d, !1) : a.attachEvent('onload', d);
})(window,document);
},
// Identify
// --------
identify : function (userId, traits) {
if (!traits) return;
// If the custom metadata object hasn't ever been made, make it.
window._errs.meta || (window._errs.meta = {});
// Add all of the traits as metadata.
if (this.settings.meta) analytics.utils.extend(window._errs.meta, traits);
}
});
// FoxMetrics
// -----------
// [Website] (http://foxmetrics.com)
// [Documentation](http://foxmetrics.com/documentation)
// [Documentation - JS](http://foxmetrics.com/documentation/apijavascript)
// [Support](http://support.foxmetrics.com)
analytics.addProvider('FoxMetrics', {
settings: {
appId: null
},
// Initialize
// ----------
initialize: function (settings) {
settings = analytics.utils.resolveSettings(settings, 'appId');
analytics.utils.extend(this.settings, settings);
var _fxm = window._fxm || {};
window._fxm = _fxm.events || [];
function _fxms(id) {
(function () {
var fxms = document.createElement('script'); fxms.type = 'text/javascript'; fxms.async = true;
fxms.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'd35tca7vmefkrc.cloudfront.net/scripts/' + id + '.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(fxms, s);
})();
}
_fxms(this.settings.appId);
},
// Identify
// --------
identify: function (userId, traits) {
// user id is required for profile updates,
// otherwise its a waste of resources as nothing will get updated
if (userId) {
// fxm needs first and last name seperately
var fname = null, lname = null, email = null;
if (traits) {
fname = traits.name.split(' ')[0];
lname = traits.name.split(' ')[1];
email = typeof (traits.email) !== 'undefined' ? traits.email : null;
}
// we should probably remove name and email before passing as attributes
window._fxm.push(['_fxm.visitor.Profile', userId, fname, lname, email, null, null, null, (traits || null)]);
}
},
// Track
// -----
track: function (event, properties) {
// send in null as event category name
window._fxm.push([event, null, properties]);
},
// Pageview
// ----------
pageview: function (url) {
// we are happy to accept traditional analytics :)
// (title, name, categoryName, url, referrer)
window._fxm.push(['_fxm.pages.view', null, null, null, (url || null), null]);
}
});
// Google Analytics
// ----------------
// [Documentation](https://developers.google.com/analytics/devguides/collection/gajs/).
analytics.addProvider('Google Analytics', {
settings : {
anonymizeIp : false,
enhancedLinkAttribution : false,
siteSpeedSampleRate : null,
domain : null,
trackingId : null
},
// Initialize
// ----------
// Changes to the Google Analytics snippet:
//
// * Added `trackingId`.
// * Added optional support for `enhancedLinkAttribution`
// * Added optional support for `siteSpeedSampleRate`
// * Added optional support for `anonymizeIp`
initialize : function (settings) {
settings = analytics.utils.resolveSettings(settings, 'trackingId');
analytics.utils.extend(this.settings, settings);