Skip to content

Commit e270c3e

Browse files
Add integration google-tag-manager This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-google-tag-manager Readme: https://github.com/segment-integrations/analytics.js-integration-google-tag-manager/blob/master/README.md
1 parent 125b4a3 commit e270c3e

File tree

6 files changed

+422
-0
lines changed

6 files changed

+422
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2.5.0 / 2017-04-27
2+
==================
3+
4+
* Remove assumesPageView option.
5+
6+
2.4.0 / 2017-03-29
7+
==================
8+
9+
* Add support for environment option
10+
11+
2.3.0 / 2016-11-07
12+
==================
13+
14+
* Bump analytics.js-integration to ^3.x which includes fix for assumePageview
15+
16+
2.2.0 / 2016-08-01
17+
==================
18+
19+
* send anonymousId automatically
20+
21+
2.1.0 / 2016-07-12
22+
==================
23+
24+
* Update Karma to 1.1.0
25+
* push userId to data layer for track calls
26+
27+
2.0.0 / 2016-06-21
28+
==================
29+
30+
* Remove Duo compatibility
31+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
32+
* Update eslint configuration
33+
34+
1.0.5 / 2016-05-07
35+
==================
36+
37+
* Bump Analytics.js core, tester, integration to use Facade 2.x
38+
39+
1.0.4 / 2015-06-30
40+
==================
41+
42+
* Replace analytics.js dependency with analytics.js-core
43+
44+
1.0.3 / 2015-06-30
45+
==================
46+
47+
* Replace analytics.js dependency with analytics.js-core
48+
49+
1.0.2 / 2015-06-24
50+
==================
51+
52+
* Bump analytics.js-integration version
53+
54+
1.0.1 / 2015-06-24
55+
==================
56+
57+
* Bump analytics.js-integration version
58+
59+
1.0.0 / 2015-06-09
60+
==================
61+
62+
* Initial commit :sparkles:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# analytics.js-integration-google-tag-manager [![Build Status][ci-badge]][ci-link]
2+
3+
Google Tag Manager integration for [Analytics.js][].
4+
5+
## License
6+
7+
Released under the [MIT license](LICENSE).
8+
9+
10+
[Analytics.js]: https://segment.com/docs/libraries/analytics.js/
11+
[ci-link]: https://circleci.com/gh/segment-integrations/analytics.js-integration-google-tag-manager
12+
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-google-tag-manager.svg?style=svg
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
var push = require('global-queue')('dataLayer', { wrap: false });
9+
10+
/**
11+
* Expose `GTM`.
12+
*/
13+
14+
var GTM = module.exports = integration('Google Tag Manager')
15+
.global('dataLayer')
16+
.global('google_tag_manager')
17+
.option('containerId', '')
18+
.option('environment', '')
19+
.option('trackNamedPages', true)
20+
.option('trackCategorizedPages', true)
21+
.tag('no-env', '<script src="//www.googletagmanager.com/gtm.js?id={{ containerId }}&l=dataLayer">')
22+
.tag('with-env', '<script src="//www.googletagmanager.com/gtm.js?id={{ containerId }}&l=dataLayer&gtm_preview={{ environment }}">');
23+
24+
/**
25+
* Initialize.
26+
*
27+
* https://developers.google.com/tag-manager
28+
*
29+
* @api public
30+
*/
31+
32+
GTM.prototype.initialize = function() {
33+
push({ 'gtm.start': Number(new Date()), event: 'gtm.js' });
34+
35+
if (this.options.environment.length) {
36+
this.load('with-env', this.options, this.ready);
37+
} else {
38+
this.load('no-env', this.options, this.ready);
39+
}
40+
};
41+
42+
/**
43+
* Loaded?
44+
*
45+
* @api private
46+
* @return {boolean}
47+
*/
48+
49+
GTM.prototype.loaded = function() {
50+
return !!(window.dataLayer && Array.prototype.push !== window.dataLayer.push);
51+
};
52+
53+
/**
54+
* Page.
55+
*
56+
* @api public
57+
* @param {Page} page
58+
*/
59+
60+
GTM.prototype.page = function(page) {
61+
var category = page.category();
62+
var name = page.fullName();
63+
var opts = this.options;
64+
65+
// all
66+
if (opts.trackAllPages) {
67+
this.track(page.track());
68+
}
69+
70+
// categorized
71+
if (category && opts.trackCategorizedPages) {
72+
this.track(page.track(category));
73+
}
74+
75+
// named
76+
if (name && opts.trackNamedPages) {
77+
this.track(page.track(name));
78+
}
79+
};
80+
81+
/**
82+
* Track.
83+
*
84+
* https://developers.google.com/tag-manager/devguide#events
85+
*
86+
* @api public
87+
* @param {Track} track
88+
*/
89+
90+
GTM.prototype.track = function(track) {
91+
var props = track.properties();
92+
var userId = this.analytics.user().id();
93+
var anonymousId = this.analytics.user().anonymousId();
94+
if (userId) props.userId = userId;
95+
if (anonymousId) props.segmentAnonymousId = anonymousId;
96+
props.event = track.event();
97+
98+
push(props);
99+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@segment/analytics.js-integration-google-tag-manager",
3+
"description": "The Google Tag Manager analytics.js integration.",
4+
"version": "2.5.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"google-tag-manager"
10+
],
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "make test"
14+
},
15+
"author": "Segment \u003cfriends@segment.com\u003e",
16+
"license": "SEE LICENSE IN LICENSE",
17+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/google-tag-manager#readme",
18+
"bugs": {
19+
"url": "https://github.com/segmentio/analytics.js-integrations/issues"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/segmentio/analytics.js-integrations.git"
24+
},
25+
"dependencies": {
26+
"@segment/analytics.js-integration": "^3.2.0",
27+
"global-queue": "^1.0.1"
28+
},
29+
"devDependencies": {
30+
"@segment/analytics.js-core": "^3.0.0",
31+
"@segment/analytics.js-integration-tester": "^3.1.0",
32+
"@segment/clear-env": "^2.0.0",
33+
"@segment/eslint-config": "^3.1.1",
34+
"browserify": "^13.0.0",
35+
"browserify-istanbul": "^2.0.0",
36+
"eslint": "^2.9.0",
37+
"eslint-plugin-mocha": "^2.2.0",
38+
"eslint-plugin-require-path-exists": "^1.1.5",
39+
"istanbul": "^0.4.3",
40+
"karma": "1.3.0",
41+
"karma-browserify": "^5.0.4",
42+
"karma-chrome-launcher": "^1.0.1",
43+
"karma-coverage": "^1.0.0",
44+
"karma-junit-reporter": "^1.0.0",
45+
"karma-mocha": "1.0.1",
46+
"karma-phantomjs-launcher": "^1.0.0",
47+
"karma-sauce-launcher": "^1.0.0",
48+
"karma-spec-reporter": "0.0.26",
49+
"mocha": "^2.2.5",
50+
"npm-check": "^5.2.1",
51+
"phantomjs-prebuilt": "^2.1.7",
52+
"watchify": "^3.7.0"
53+
}
54+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@segment/eslint-config/mocha"
3+
}

0 commit comments

Comments
 (0)