Skip to content

Commit dcae72c

Browse files
committed
Merge pull request #23 from dominikmatt/develop
v0.4.0
2 parents 1cf808b + d6b758e commit dcae72c

File tree

6 files changed

+195
-63
lines changed

6 files changed

+195
-63
lines changed

bower.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trackingJS",
3-
"version": "0.3.5",
3+
"version": "0.4.0",
44
"homepage": "https://github.com/dominikmatt/trackingJS",
55
"authors": [
66
"Dominik Matt <[email protected]>"
@@ -12,7 +12,10 @@
1212
"universal analytics",
1313
"tracking",
1414
"track",
15-
"eCommerce"
15+
"eCommerce",
16+
"event",
17+
"event bundle"
1618
],
17-
"license": "Apache License"
19+
"license": "Apache License",
20+
"ignore": []
1821
}

example/eventBundle.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>trackingJS event bundle</title>
5+
</head>
6+
<body>
7+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
8+
<script src="/scripts/adapter/ua.js"></script>
9+
<script src="/scripts/tracking.js"></script>
10+
<script src="/scripts/eventBundle/authBundle.js"></script>
11+
12+
<script type="text/javascript">
13+
var trackingJS = new trackingJS({
14+
namespace: 'bundle',
15+
type: 'ua',
16+
analyticsCode: 'UA-57009541-1',
17+
url: 'auto',
18+
pageview: false,
19+
anonymizeIp: false,
20+
eventBundles: ['auth']
21+
});
22+
23+
24+
//trackingJS.pageview('test/1', 'test title1');
25+
26+
//trackingJS.event('category1', 'action', 'label', 1);
27+
trackingJS.bundles.auth.setData('myUsername', 'myUserId');
28+
trackingJS.bundles.auth.signup();
29+
trackingJS.bundles.auth.signin();
30+
trackingJS.bundles.auth.signout();
31+
32+
</script>
33+
</body>
34+
</html>

scripts/adapter/ua.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var uaTrackingJS = function(trackingJSOptions, trackingJSHelper) {
44
* initialize
55
*/
66
this.init = function (namespace, code, url, pageview) {
7+
this.namespace = namespace;
78
var options = {
89
name: namespace
910
};
@@ -30,15 +31,7 @@ var uaTrackingJS = function(trackingJSOptions, trackingJSHelper) {
3031
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
3132
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
3233
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
33-
}
34-
35-
return {
36-
init: this.init,
37-
appendAnalyticsJs: this.appendAnalyticsJs,
38-
pageview: this.pageview,
39-
event: this.event,
40-
eCommerce: this.eCommerce
41-
}
34+
};
4235
};
4336

4437
/**
@@ -47,7 +40,7 @@ var uaTrackingJS = function(trackingJSOptions, trackingJSHelper) {
4740
* @param page
4841
* @param title
4942
*/
50-
uaTrackingJS.prototype.pageview = function(namespace, page, title) {
43+
uaTrackingJS.prototype.pageview = function(page, title) {
5144
var options = {};
5245

5346

@@ -60,7 +53,7 @@ uaTrackingJS.prototype.pageview = function(namespace, page, title) {
6053
}
6154

6255

63-
ga(namespace + '.send', 'pageview', options);
56+
ga(this.namespace + '.send', 'pageview', options);
6457
};
6558

6659
/**
@@ -71,7 +64,7 @@ uaTrackingJS.prototype.pageview = function(namespace, page, title) {
7164
* @param label
7265
* @param value
7366
*/
74-
uaTrackingJS.prototype.event = function(namespace, category, action, label, value) {
67+
uaTrackingJS.prototype.event = function(category, action, label, value) {
7568
var options = {
7669
'hitType': 'event',
7770
eventCategory: category,
@@ -86,7 +79,7 @@ uaTrackingJS.prototype.event = function(namespace, category, action, label, valu
8679
options.eventValue = value;
8780
}
8881

89-
ga(namespace + '.send', options);
82+
ga(this.namespace + '.send', options);
9083
};
9184

9285
/**
@@ -170,4 +163,13 @@ uaTrackingJS.prototype.eCommerce = {
170163
send: function() {
171164
ga(this.trackingJS.getNamespace() + '.ecommerce:send');
172165
}
166+
};
167+
168+
/**
169+
* setUserId
170+
*
171+
* @param userId
172+
*/
173+
uaTrackingJS.prototype.setUserId = function(userId) {
174+
ga(this.namespace + '.set', 'userId', userId);
173175
};

scripts/eventBundle/authBundle.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Auth Bundle
3+
*/
4+
trackingJS.prototype.eventBundles.auth = function() {
5+
this.dataName = 'auth';
6+
this.username = '';
7+
this.userId = '';
8+
9+
this.init = function init(tracking) {
10+
this.tracking = tracking;
11+
console.log('init bundle auth :)');
12+
};
13+
14+
this.setData = function setData(username, userId) {
15+
this.username = username;
16+
this.userId = userId;
17+
};
18+
19+
this.signin = function signin() {
20+
this.tracking.event('User', 'User - Signin', 'Success: ' + this.username);
21+
this.tracking.setUserId(this.userId);
22+
};
23+
24+
this.signout = function signout() {
25+
this.tracking.event('User', 'User - Signout', 'Success: ' + this.username);
26+
this.tracking.setUserId('');
27+
};
28+
29+
this.signup = function signup() {
30+
this.tracking.event('User', 'User - Signup', 'Success: ' + this.username);
31+
};
32+
};

scripts/eventBundle/exampleBundle.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Example bundle
3+
*/
4+
trackingJS.eventBundles.exampleBundle = function() {
5+
this.dataName = 'example';
6+
this.$el = null;
7+
8+
/**
9+
*
10+
*/
11+
this.init = function(core, callback) {
12+
console.log('init bundle example :)');
13+
select();
14+
callback(this.$el)
15+
};
16+
17+
/**
18+
*
19+
* @returns {boolean}
20+
*/
21+
var select = function() {
22+
this.$el = $('[data-trackingjs-example]');
23+
24+
return true;
25+
};
26+
27+
/**
28+
*
29+
* @param el
30+
*/
31+
this.getData = function() {
32+
33+
}
34+
35+
36+
};

0 commit comments

Comments
 (0)