Skip to content

Commit

Permalink
Add integration adwords
Browse files Browse the repository at this point in the history
  • Loading branch information
SegmentDestinationsBot committed Dec 10, 2019
1 parent 7226576 commit 81846a3
Show file tree
Hide file tree
Showing 6 changed files with 585 additions and 0 deletions.
84 changes: 84 additions & 0 deletions integrations/adwords/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

2.5.2 / 2018-02-23
==================

* prep for mixed component migration

2.5.1 / 2017-10-30
==================

* tag bump
* Merge pull request #16 from segment-integrations/adwords-multiple-ids

2.5.0 / 2017-10-30
==================

* Merge pull request #16 from segment-integrations/adwords-multiple-ids

2.4.0 / 2017-01-05
==================

* Support sending standalone Remarketing Tags


2.3.0 / 2016-11-16
==================

* Support Dynamic Remarketing Tags

2.2.0 / 2016-11-15
==================

* Prevent Adwords from crashing due to adblockers

2.1.1 / 2016-09-22
==================

* Revert "Dynamic remarketing"

2.1.0 / 2016-09-15
==================

* support dynamic remarketing

2.0.0 / 2016-06-21
==================

* Remove Duo compatibility
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
* Update eslint configuration

1.0.6 / 2016-05-07
==================

* Bump Analytics.js core, tester, integration to use Facade 2.x

1.0.5 / 2015-08-27
==================

* add check for google_trackConversion in loaded function.

1.0.4 / 2015-06-30
==================

* Replace analytics.js dependency with analytics.js-core

1.0.3 / 2015-06-30
==================

* Replace analytics.js dependency with analytics.js-core

1.0.2 / 2015-06-24
==================

* Bump analytics.js-integration version

1.0.1 / 2015-06-24
==================

* Bump analytics.js-integration version

1.0.0 / 2015-06-09
==================

* Initial commit :sparkles:
12 changes: 12 additions & 0 deletions integrations/adwords/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# analytics.js-integration-adwords [![Build Status][ci-badge]][ci-link]

Adwords integration for [Analytics.js][].

## License

Released under the [MIT license](LICENSE).


[Analytics.js]: https://segment.com/docs/libraries/analytics.js/
[ci-link]: https://circleci.com/gh/segment-integrations/analytics.js-integration-adwords
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-adwords.svg?style=svg
154 changes: 154 additions & 0 deletions integrations/adwords/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
'use strict';

/**
* Module dependencies.
*/

var integration = require('@segment/analytics.js-integration');
var when = require('do-when');

/**
* Expose `AdWords`.
*/

var AdWords = module.exports = integration('AdWords')
.option('conversionId', '')
.option('pageRemarketing', false)
.option('eventMappings', [])
.tag('<script src="//www.googleadservices.com/pagead/conversion_async.js">');

/**
* Initialize.
*
* @api public
*/

AdWords.prototype.initialize = function() {
var loaded = this.loaded;
var ready = this.ready;
this.load(function() {
when(loaded, ready);
});
};

/**
* Loaded.
*
* @api private
* @return {boolean}
*/

AdWords.prototype.loaded = function() {
return !!(document.body && window.google_trackConversion);
};

/**
* Page.
*
* https://support.google.com/adwords/answer/3111920#standard_parameters
* https://support.google.com/adwords/answer/3103357
* https://developers.google.com/adwords-remarketing-tag/asynchronous/
* https://developers.google.com/adwords-remarketing-tag/parameters
*
* @api public
* @param {Page} page
*/

AdWords.prototype.page = function(page) {
// Remarketing option can support both Adwords' "static" or "dynamic" remarketing tags
// Difference is static you don't need to send props under `google_custom_params`
var remarketing = this.options.pageRemarketing;
var id = this.options.conversionId;
var props = page.properties();

// Conversion tag
window.google_trackConversion({
google_conversion_id: id,
google_custom_params: {},
google_remarketing_only: false // this ensures that this is a conversion tag
});

// Remarketing tag (must be sent in _addition_ to any conversion tags)
// https://developers.google.com/adwords-remarketing-tag/
if (remarketing) {
window.google_trackConversion({
google_conversion_id: id,
google_custom_params: props,
google_remarketing_only: true // this ensures that this is a remarketing tag
});
}
};

/**
* Track.
*
* @api public
* @param {Track}
*/

AdWords.prototype.track = function(track) {
var self = this;
var props = track.properties();
var eventMappings = this.options.eventMappings;
var revenue = track.revenue() || 0;

eventMappings.forEach(function(mapping) {
if (mapping.value) {
if (mapping.value.eventName.toLowerCase() !== track.event().toLowerCase()) return;
var id = mapping.value.conversionId || self.options.conversionId; // customer can either specify one global conversion id or one per mapping

// Fire conversion tag
if (mapping.value.label !== '') {
delete props.revenue;

window.google_trackConversion({
google_conversion_id: id,
google_custom_params: props,
google_conversion_language: 'en',
google_conversion_format: '3',
google_conversion_color: 'ffffff',
google_conversion_label: mapping.value.label,
google_conversion_value: revenue,
google_remarketing_only: false // ensure this is a conversion tag
});
}

// Fire remarketing tag
if (mapping.value.remarketing) {
window.google_trackConversion({
google_conversion_id: id,
google_custom_params: props, // do not send PII here!
google_remarketing_only: true // ensure this is a remarketing tag
});
}
} else {
if (mapping.eventName.toLowerCase() !== track.event().toLowerCase()) return;
id = mapping.conversionId || self.options.conversionId; // customer can either specify one global conversion id or one per mapping

// Fire conversion tag
if (mapping.label !== '') {
delete props.revenue;

window.google_trackConversion({
google_conversion_id: id,
google_custom_params: props,
google_conversion_language: 'en',
google_conversion_format: '3',
google_conversion_color: 'ffffff',
google_conversion_label: mapping.label,
google_conversion_value: revenue,
google_remarketing_only: false // ensure this is a conversion tag
});
}

// Fire remarketing tag
if (mapping.remarketing) {
window.google_trackConversion({
google_conversion_id: id,
google_custom_params: props, // do not send PII here!
google_remarketing_only: true // ensure this is a remarketing tag
});
}
}
});
};
55 changes: 55 additions & 0 deletions integrations/adwords/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@segment/analytics.js-integration-adwords",
"description": "The Adwords analytics.js integration.",
"version": "2.5.2",
"keywords": [
"analytics.js",
"analytics.js-integration",
"segment",
"adwords"
],
"main": "lib/index.js",
"scripts": {
"test": "make test"
},
"author": "Segment \u003c[email protected]\u003e",
"license": "SEE LICENSE IN LICENSE",
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/adwords#readme",
"bugs": {
"url": "https://github.com/segmentio/analytics.js-integrations/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/segmentio/analytics.js-integrations.git"
},
"dependencies": {
"@ndhoule/each": "^2.0.1",
"@segment/analytics.js-integration": "^2.1.0",
"do-when": "^1.0.0"
},
"devDependencies": {
"@segment/analytics.js-core": "^3.0.0",
"@segment/analytics.js-integration-tester": "^3.1.0",
"@segment/clear-env": "^2.0.0",
"@segment/eslint-config": "^3.1.1",
"browserify": "^13.0.0",
"browserify-istanbul": "^2.0.0",
"eslint": "^2.9.0",
"eslint-plugin-mocha": "^2.2.0",
"eslint-plugin-require-path-exists": "^1.1.5",
"istanbul": "^0.4.3",
"karma": "1.3.0",
"karma-browserify": "^5.0.4",
"karma-chrome-launcher": "^1.0.1",
"karma-coverage": "^1.0.0",
"karma-junit-reporter": "^1.0.0",
"karma-mocha": "1.0.1",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.0.0",
"karma-spec-reporter": "0.0.26",
"mocha": "^2.2.5",
"npm-check": "^5.2.1",
"phantomjs-prebuilt": "^2.1.7",
"watchify": "^3.7.0"
}
}
3 changes: 3 additions & 0 deletions integrations/adwords/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@segment/eslint-config/mocha"
}
Loading

0 comments on commit 81846a3

Please sign in to comment.