Skip to content

Commit 81846a3

Browse files
Add integration adwords This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-adwords Readme: https://github.com/segment-integrations/analytics.js-integration-adwords/blob/master/README.md
1 parent 7226576 commit 81846a3

File tree

6 files changed

+585
-0
lines changed

6 files changed

+585
-0
lines changed

integrations/adwords/HISTORY.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
2.5.2 / 2018-02-23
3+
==================
4+
5+
* prep for mixed component migration
6+
7+
2.5.1 / 2017-10-30
8+
==================
9+
10+
* tag bump
11+
* Merge pull request #16 from segment-integrations/adwords-multiple-ids
12+
13+
2.5.0 / 2017-10-30
14+
==================
15+
16+
* Merge pull request #16 from segment-integrations/adwords-multiple-ids
17+
18+
2.4.0 / 2017-01-05
19+
==================
20+
21+
* Support sending standalone Remarketing Tags
22+
23+
24+
2.3.0 / 2016-11-16
25+
==================
26+
27+
* Support Dynamic Remarketing Tags
28+
29+
2.2.0 / 2016-11-15
30+
==================
31+
32+
* Prevent Adwords from crashing due to adblockers
33+
34+
2.1.1 / 2016-09-22
35+
==================
36+
37+
* Revert "Dynamic remarketing"
38+
39+
2.1.0 / 2016-09-15
40+
==================
41+
42+
* support dynamic remarketing
43+
44+
2.0.0 / 2016-06-21
45+
==================
46+
47+
* Remove Duo compatibility
48+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
49+
* Update eslint configuration
50+
51+
1.0.6 / 2016-05-07
52+
==================
53+
54+
* Bump Analytics.js core, tester, integration to use Facade 2.x
55+
56+
1.0.5 / 2015-08-27
57+
==================
58+
59+
* add check for google_trackConversion in loaded function.
60+
61+
1.0.4 / 2015-06-30
62+
==================
63+
64+
* Replace analytics.js dependency with analytics.js-core
65+
66+
1.0.3 / 2015-06-30
67+
==================
68+
69+
* Replace analytics.js dependency with analytics.js-core
70+
71+
1.0.2 / 2015-06-24
72+
==================
73+
74+
* Bump analytics.js-integration version
75+
76+
1.0.1 / 2015-06-24
77+
==================
78+
79+
* Bump analytics.js-integration version
80+
81+
1.0.0 / 2015-06-09
82+
==================
83+
84+
* Initial commit :sparkles:

integrations/adwords/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# analytics.js-integration-adwords [![Build Status][ci-badge]][ci-link]
2+
3+
Adwords 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-adwords
12+
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-adwords.svg?style=svg

integrations/adwords/lib/index.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
var when = require('do-when');
9+
10+
/**
11+
* Expose `AdWords`.
12+
*/
13+
14+
var AdWords = module.exports = integration('AdWords')
15+
.option('conversionId', '')
16+
.option('pageRemarketing', false)
17+
.option('eventMappings', [])
18+
.tag('<script src="//www.googleadservices.com/pagead/conversion_async.js">');
19+
20+
/**
21+
* Initialize.
22+
*
23+
* @api public
24+
*/
25+
26+
AdWords.prototype.initialize = function() {
27+
var loaded = this.loaded;
28+
var ready = this.ready;
29+
this.load(function() {
30+
when(loaded, ready);
31+
});
32+
};
33+
34+
/**
35+
* Loaded.
36+
*
37+
* @api private
38+
* @return {boolean}
39+
*/
40+
41+
AdWords.prototype.loaded = function() {
42+
return !!(document.body && window.google_trackConversion);
43+
};
44+
45+
/**
46+
* Page.
47+
*
48+
* https://support.google.com/adwords/answer/3111920#standard_parameters
49+
* https://support.google.com/adwords/answer/3103357
50+
* https://developers.google.com/adwords-remarketing-tag/asynchronous/
51+
* https://developers.google.com/adwords-remarketing-tag/parameters
52+
*
53+
* @api public
54+
* @param {Page} page
55+
*/
56+
57+
AdWords.prototype.page = function(page) {
58+
// Remarketing option can support both Adwords' "static" or "dynamic" remarketing tags
59+
// Difference is static you don't need to send props under `google_custom_params`
60+
var remarketing = this.options.pageRemarketing;
61+
var id = this.options.conversionId;
62+
var props = page.properties();
63+
64+
// Conversion tag
65+
window.google_trackConversion({
66+
google_conversion_id: id,
67+
google_custom_params: {},
68+
google_remarketing_only: false // this ensures that this is a conversion tag
69+
});
70+
71+
// Remarketing tag (must be sent in _addition_ to any conversion tags)
72+
// https://developers.google.com/adwords-remarketing-tag/
73+
if (remarketing) {
74+
window.google_trackConversion({
75+
google_conversion_id: id,
76+
google_custom_params: props,
77+
google_remarketing_only: true // this ensures that this is a remarketing tag
78+
});
79+
}
80+
};
81+
82+
/**
83+
* Track.
84+
*
85+
* @api public
86+
* @param {Track}
87+
*/
88+
89+
AdWords.prototype.track = function(track) {
90+
var self = this;
91+
var props = track.properties();
92+
var eventMappings = this.options.eventMappings;
93+
var revenue = track.revenue() || 0;
94+
95+
eventMappings.forEach(function(mapping) {
96+
if (mapping.value) {
97+
if (mapping.value.eventName.toLowerCase() !== track.event().toLowerCase()) return;
98+
var id = mapping.value.conversionId || self.options.conversionId; // customer can either specify one global conversion id or one per mapping
99+
100+
// Fire conversion tag
101+
if (mapping.value.label !== '') {
102+
delete props.revenue;
103+
104+
window.google_trackConversion({
105+
google_conversion_id: id,
106+
google_custom_params: props,
107+
google_conversion_language: 'en',
108+
google_conversion_format: '3',
109+
google_conversion_color: 'ffffff',
110+
google_conversion_label: mapping.value.label,
111+
google_conversion_value: revenue,
112+
google_remarketing_only: false // ensure this is a conversion tag
113+
});
114+
}
115+
116+
// Fire remarketing tag
117+
if (mapping.value.remarketing) {
118+
window.google_trackConversion({
119+
google_conversion_id: id,
120+
google_custom_params: props, // do not send PII here!
121+
google_remarketing_only: true // ensure this is a remarketing tag
122+
});
123+
}
124+
} else {
125+
if (mapping.eventName.toLowerCase() !== track.event().toLowerCase()) return;
126+
id = mapping.conversionId || self.options.conversionId; // customer can either specify one global conversion id or one per mapping
127+
128+
// Fire conversion tag
129+
if (mapping.label !== '') {
130+
delete props.revenue;
131+
132+
window.google_trackConversion({
133+
google_conversion_id: id,
134+
google_custom_params: props,
135+
google_conversion_language: 'en',
136+
google_conversion_format: '3',
137+
google_conversion_color: 'ffffff',
138+
google_conversion_label: mapping.label,
139+
google_conversion_value: revenue,
140+
google_remarketing_only: false // ensure this is a conversion tag
141+
});
142+
}
143+
144+
// Fire remarketing tag
145+
if (mapping.remarketing) {
146+
window.google_trackConversion({
147+
google_conversion_id: id,
148+
google_custom_params: props, // do not send PII here!
149+
google_remarketing_only: true // ensure this is a remarketing tag
150+
});
151+
}
152+
}
153+
});
154+
};

integrations/adwords/package.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "@segment/analytics.js-integration-adwords",
3+
"description": "The Adwords analytics.js integration.",
4+
"version": "2.5.2",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"adwords"
10+
],
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "make test"
14+
},
15+
"author": "Segment \u003c[email protected]\u003e",
16+
"license": "SEE LICENSE IN LICENSE",
17+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/adwords#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+
"@ndhoule/each": "^2.0.1",
27+
"@segment/analytics.js-integration": "^2.1.0",
28+
"do-when": "^1.0.0"
29+
},
30+
"devDependencies": {
31+
"@segment/analytics.js-core": "^3.0.0",
32+
"@segment/analytics.js-integration-tester": "^3.1.0",
33+
"@segment/clear-env": "^2.0.0",
34+
"@segment/eslint-config": "^3.1.1",
35+
"browserify": "^13.0.0",
36+
"browserify-istanbul": "^2.0.0",
37+
"eslint": "^2.9.0",
38+
"eslint-plugin-mocha": "^2.2.0",
39+
"eslint-plugin-require-path-exists": "^1.1.5",
40+
"istanbul": "^0.4.3",
41+
"karma": "1.3.0",
42+
"karma-browserify": "^5.0.4",
43+
"karma-chrome-launcher": "^1.0.1",
44+
"karma-coverage": "^1.0.0",
45+
"karma-junit-reporter": "^1.0.0",
46+
"karma-mocha": "1.0.1",
47+
"karma-phantomjs-launcher": "^1.0.0",
48+
"karma-sauce-launcher": "^1.0.0",
49+
"karma-spec-reporter": "0.0.26",
50+
"mocha": "^2.2.5",
51+
"npm-check": "^5.2.1",
52+
"phantomjs-prebuilt": "^2.1.7",
53+
"watchify": "^3.7.0"
54+
}
55+
}

integrations/adwords/test/.eslintrc

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)