Skip to content

Commit 308baaa

Browse files
committed
Merge pull request #38 from dominikmatt/develop
v 0.5.0
2 parents f0a535b + a63fe91 commit 308baaa

File tree

5 files changed

+92
-12
lines changed

5 files changed

+92
-12
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ is for the event register we can set on the default on data-trackingjs=""
4343

4444

4545
###debug
46-
*Default*: (boolean) false
46+
*Default*: (boolean) false
4747
view debug messages
4848

4949
###anonymizeIp
@@ -54,6 +54,10 @@ view debug messages
5454
*Default:* (array)
5555
(array) | name of the bundles
5656

57+
###set
58+
*Default*: (object) {}
59+
(object) {} | visit: https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#set
60+
5761
##Using
5862

5963
### Default tracking

example/default.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<!DOCTYOE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
4-
4+
<title>defaults - TrackingJS</title>
55
</head>
66
<body>
77

@@ -18,7 +18,10 @@
1818
analyticsCode: 'UA-57009541-1',
1919
url: 'auto',
2020
pageview: false,
21-
anonymizeIp: true
21+
anonymizeIp: true,
22+
set: {
23+
dimension1: 'dimension test'
24+
}
2225
});
2326

2427

scripts/adapter/ua.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var uaTrackingJS = function(trackingJSOptions, trackingJSHelper) {
33
/**
44
* initialize
55
*/
6-
this.init = function (namespace, code, url, pageview) {
6+
this.init = function (namespace, code, url) {
77
this.namespace = namespace;
88
var options = {
99
name: namespace
@@ -17,10 +17,6 @@ var uaTrackingJS = function(trackingJSOptions, trackingJSHelper) {
1717
} else {
1818
trackingJSHelper.info(options.name + ' ip is not anonymous');
1919
}
20-
21-
if(pageview === true) {
22-
this.pageview(options.name);
23-
}
2420
}.bind(this),
2521

2622
/**
@@ -187,4 +183,16 @@ uaTrackingJS.prototype.eCommerce = {
187183
*/
188184
uaTrackingJS.prototype.setUserId = function(userId) {
189185
ga(this.namespace + '.set', 'userId', userId);
190-
};
186+
};
187+
188+
/**
189+
* @method set
190+
*
191+
* @param {string} key
192+
* @param {string} value
193+
*/
194+
uaTrackingJS.prototype.set = function(set) {
195+
if(typeof set === 'object') {
196+
ga(this.namespace + '.set', set);
197+
}
198+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* socialshare Bundle
3+
*
4+
* @author Phuc Le <[email protected]>
5+
*/
6+
trackingJS.prototype.eventBundles.socialshare = function() {
7+
this.bundleName = 'socialshare';
8+
9+
/**
10+
* @mehtod init
11+
*
12+
* @param tracking
13+
*/
14+
this.init = function init(tracking) {
15+
this.tracking = tracking;
16+
bindDomEvents();
17+
};
18+
19+
/**
20+
* @method bindDomEvents
21+
*
22+
* @type {function(this:trackingJS.prototype.eventBundles)}
23+
*/
24+
var bindDomEvents = function() {
25+
$('body').on('click', '[data-type="share"]', socialshareHandler.bind(this));
26+
}.bind(this);
27+
28+
/**
29+
* @method socialshareHandler
30+
*
31+
* @param event
32+
*/
33+
var socialshareHandler = function(event) {
34+
var $el = $(event.currentTarget),
35+
platform = $el.data('platform');
36+
37+
this.tracking.event(
38+
'Social Media',
39+
'Social Media - ' + platform + ' Share',
40+
'Social Media: ' + platform + ' Share'
41+
);
42+
}
43+
};

scripts/tracking.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var trackingJS = function (options) {
1717
dataName: 'trackingjs',
1818
debug: false,
1919
anonymizeIp: false,
20-
eventBundles: []
20+
eventBundles: [],
21+
set: {}
2122
}, options);
2223

2324
/**
@@ -32,9 +33,16 @@ var trackingJS = function (options) {
3233

3334
loadAdapter();
3435
loadEventBundles();
36+
3537
if (this.tracking && typeof this.tracking == 'object') {
3638
this.tracking.appendAnalyticsJs();
37-
this.tracking.init(settings.namespace, settings.analyticsCode, settings.url, settings.pageview);
39+
this.tracking.init(settings.namespace, settings.analyticsCode, settings.url);
40+
this.setTrackingVars(settings.set);
41+
42+
if(settings.pageview === true) {
43+
this.tracking.pageview(options.name);
44+
}
45+
3846
this.registerEvents();
3947
} else {
4048
throw 'Tracking type not loaded';
@@ -204,6 +212,15 @@ trackingJS.prototype.event = function (category, action, label, value, callback)
204212
this.tracking.event(category, action, label, value, callback);
205213
};
206214

215+
/**
216+
* @method setTrackingVars
217+
*/
218+
trackingJS.prototype.setTrackingVars = function(vars) {
219+
if(!!vars) {
220+
this.tracking.set(vars);
221+
}
222+
};
223+
207224
/**
208225
* register eCommerce Plugin
209226
*
@@ -262,6 +279,11 @@ trackingJS.prototype.updateEvents = function () {
262279
this.registerEvents();
263280
};
264281

282+
/**
283+
* @method getNamespace
284+
*
285+
* @return {string} namespace
286+
*/
265287
trackingJS.prototype.getNamespace = function () {
266288
return this.namespace;
267289
};

0 commit comments

Comments
 (0)