PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/red/modules/tracking/omniture.tracking.js

http://github.com/ff0000/rosy
JavaScript | 94 lines | 56 code | 27 blank | 11 comment | 8 complexity | 1de9b28177e5954603ab0ade299e3600 MD5 | raw file
 1// ### Part of the [Rosy Framework](http://github.com/ff0000/rosy)
 2/* omniture.tracking.js */
 3
 4// ## Local Namespace
 5var red = red || {};
 6
 7red.module = red.module || {};
 8
 9red.module.tracking = red.module.tracking || {};
10
11
12/**
13 * Omniture and GA tracking event wrappers
14 * REQUIRES 
15	- ssla-analytics/  (this file loads ssla-analytics/analytics.min.js)
16	
17 */
18(function () {
19	
20	red.module.tracking.Omniture = (function () {
21
22		return red.Module.extend({
23			
24
25			_tracker : null,
26
27			vars : {
28				debug : true, // set to false for production
29				media_url : null //defaults to <link rel="media-url"' content="{{STATIC_URL}}" />
30			},
31
32			log : function () {
33				if (this.vars.debug) {
34					try {
35						console.log(arguments);
36					} catch (e) {}
37				}
38			},
39
40
41			init : function () {
42				this.loadJSDK();
43
44				$.subscribe("track", $.proxy(this.track, this));
45			},
46
47			track : function (e, data) {
48				this.log("o track is not setup yet =(", data.type, data);
49
50			},
51
52			onReady : function () {
53				var i,
54					account;
55
56				this.tracker = new window.ssla.analytics.Omniture({}, window.s); // pass in an optional Library object
57
58				if (this.vars.accounts) { // set account relationships passed in init()
59					for (i = this.vars.accounts.length - 1; i >= 0; i--) {
60						account = this.vars.accounts[i];
61						window.ssla.analytics.Omniture.addAccount(account[0], account[1]);
62					}
63				}
64			},
65
66			loadJSDK : function () {
67
68				this.vars.media_url = this.vars.media_url || $('link[rel="media-url"]').attr("href");
69
70				if (!this.vars.media_url) {
71					throw "tracking:Omniture missing MEDIA_URL";
72				}
73
74				Modernizr.load([{
75					load : [
76						this.vars.media_url + "js/red/modules/tracking/ssla-analytics/analytics.min.js"
77						/*this.vars.media_url + "js/red/modules/tracking/ssla-analytics/source/analytics.js",
78						this.vars.media_url + "js/red/modules/tracking/ssla-analytics/source/s_code.js"*/
79					],
80					complete : $.proxy(this.onReady, this)
81				}]);
82			},
83
84			destroy : function () {
85				$.unsubscribe("track", $.proxy(this.track, this));
86				
87				this.tracker = null;
88				this.vars = null;
89			}
90
91		});
92	}.call(red.module.tracking));
93
94}());