Skip to content

Commit f1043f7

Browse files
author
Chris Nixon
authored
Migrate doubleclick (#141)
* Initial commit * Release 1.0.0 * Initial Release! * Release 1.1.0 * Switch from img tag to container iframe * Release 1.2.0 * use https * Pin karma, karma-mocha dev dependencies (#4) * Release 1.2.1 * use fls tag * Release 1.2.2 * fix tag * Release 1.2.3 * fix url * Add support for .page events (#9) * Add support for .page events * release commit * Release 1.4.0 * support sales tags * Add property lookup (#11) * Add support for custom property lookup * Add support for custom property lookup * Release commit * Linted * Remove ie8 testing * Update option property names * prep for mixed component migration (#12) * prep for mixed component migration * test fixes * Add doubleclick back to monorepo * Run formatter * Rename karma conf ci file
1 parent bc85cb5 commit f1043f7

File tree

9 files changed

+729
-5
lines changed

9 files changed

+729
-5
lines changed

Diff for: integrations/doubleclick-floodlight/HISTORY.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
1.4.2 / 2018-02-23
2+
==================
3+
4+
* Prep for mixed component migration
5+
6+
1.4.1 / 2018-01-24
7+
==================
8+
9+
* Add support for propery lookup settings and source level tag details.
10+
11+
1.4.0 / 2017-06-22
12+
==================
13+
14+
* Support counter and sales tags.
15+
16+
1.3.0 / 2017-05-10
17+
==================
18+
19+
* Support page calls as conversion events.
20+
21+
1.2.3 / 2017-04-07
22+
==================
23+
24+
* Use iframe url
25+
26+
1.2.2 / 2017-04-07
27+
==================
28+
29+
* Add advertising ID again in the tag
30+
31+
1.2.1 / 2017-04-05
32+
==================
33+
34+
* Use fls. tag vs ad. tag
35+
36+
1.2.0 / 2017-04-04
37+
==================
38+
39+
* Enforce using https
40+
41+
1.1.0 / 2016-11-09
42+
==================
43+
44+
* Switch to iframes over image tags to allow more custom implementation!
45+
46+
1.0.0 / 2016-11-09
47+
==================
48+
49+
* Initial Release!

Diff for: integrations/doubleclick-floodlight/README.md

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

Diff for: integrations/doubleclick-floodlight/karma.conf-ci.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../karma.conf-ci.js');

Diff for: integrations/doubleclick-floodlight/karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../karma.conf');

Diff for: integrations/doubleclick-floodlight/lib/index.js

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
'use strict';
2+
3+
/**
4+
* Module Dependencies
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
var each = require('@ndhoule/each');
9+
var foldl = require('@ndhoule/foldl');
10+
var qs = require('component-querystring');
11+
var find = require('obj-case').find;
12+
var toNoCase = require('to-no-case');
13+
14+
/**
15+
* Expose `DoubleClick Floodlight` integration.
16+
*/
17+
18+
var Floodlight = (module.exports = integration('DoubleClick Floodlight')
19+
.option('source', '')
20+
.tag(
21+
'counter',
22+
'<iframe src="https://{{ src }}.fls.doubleclick.net/activityi;src={{ src }};type={{ type }};cat={{ cat }};dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;ord={{ ord }}{{ customVariables }}?">'
23+
)
24+
.tag(
25+
'sales',
26+
'<iframe src="https://{{ src }}.fls.doubleclick.net/activityi;src={{ src }};type={{ type }};cat={{ cat }};qty={{ qty }};cost={{ cost }};dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;ord={{ ord }}{{ customVariables }}?">'
27+
));
28+
29+
/**
30+
* Initialize.
31+
*
32+
* https://support.google.com/dcm/partner/answer/4293719?hl=en&ref_topic=4241548
33+
* @api public
34+
*/
35+
36+
Floodlight.prototype.initialize = function() {
37+
this.ready();
38+
};
39+
40+
/**
41+
* Track
42+
* Fire Floodlight image tags per Segment event
43+
*
44+
* https://support.google.com/dcm/partner/answer/2823425?hl=en&ref_topic=4241548
45+
* https://support.google.com/dcm/partner/answer/2823363
46+
* @api public
47+
* @param {Track}
48+
*/
49+
50+
Floodlight.prototype.track = function(track) {
51+
var mappedEvents = [];
52+
if (!this.options.events || !this.options.events.length) return;
53+
54+
// retrieve event mappings that match the current event
55+
for (var i = 0; i < this.options.events.length; i += 1) {
56+
var item = this.options.events[i];
57+
if (item.value) {
58+
if (toNoCase(item.key) === toNoCase(track.event()))
59+
mappedEvents.push(item.value);
60+
} else if (toNoCase(item.event) === toNoCase(track.event())) {
61+
mappedEvents.push(item);
62+
}
63+
}
64+
var settings = this.options;
65+
66+
// Must have events mapped and DoubleClick Advertiser ID
67+
if (!mappedEvents.length || !settings.source) return;
68+
var properties = track.properties();
69+
var self = this;
70+
71+
// Prepare tag params for each mapped Floodlight Activity
72+
var tags = foldl(
73+
function(conversions, tag) {
74+
var type = tag.type || settings.groupTag;
75+
var event = tag.event;
76+
var cat = tag.cat || settings.activityTag;
77+
78+
if (!event || !cat || !type) return conversions;
79+
80+
// Find matching properties if any
81+
var matchedVariables = {};
82+
each(function(variable) {
83+
var floodlightProp = variable.value;
84+
var segmentProp = variable.key.match(/{{(.*)}}/) || variable.key;
85+
var segmentPropValue;
86+
87+
if (Array.isArray(segmentProp)) {
88+
segmentProp = segmentProp.pop();
89+
segmentPropValue = find(track.json(), segmentProp);
90+
} else {
91+
segmentPropValue = properties[segmentProp];
92+
}
93+
94+
if (segmentPropValue) {
95+
matchedVariables[floodlightProp] = segmentPropValue;
96+
}
97+
}, tag.customVariable);
98+
99+
var customVariables = qs.stringify(matchedVariables).replace(/&/g, ';');
100+
if (tag.customVariable.length) customVariables = ';' + customVariables;
101+
102+
var tagParams = {
103+
src: settings.source,
104+
type: type,
105+
cat: cat,
106+
customVariables: customVariables
107+
};
108+
109+
// there are two types of tags: counter and sales
110+
// counter basically are used to increment conversions
111+
// sales tags are used to collect revenue/cost data
112+
// ord for counter tags are cachebuster but for sales tag it is whatever you specified in your settings
113+
// sales tags takes some additional semantic ecommerce params
114+
if (tag.isSalesTag) {
115+
tagParams._type = 'sales';
116+
// you need to enable order ID reporting for sales tag inside dbl click UI if you want this to work properly
117+
var quantity = 0;
118+
if (track.products().length) {
119+
each(function(product) {
120+
quantity += product.quantity || 0;
121+
}, track.products());
122+
} else if (properties.quantity) {
123+
quantity = properties.quantity;
124+
}
125+
if (quantity) tagParams.qty = quantity;
126+
// doubleclick wants revenue under this cost param, yes
127+
if (track.revenue()) tagParams.cost = track.revenue();
128+
tagParams.ord = track.proxy(tag.ordKey);
129+
} else {
130+
tagParams.ord = Math.random() * 10000000000000000000;
131+
}
132+
133+
conversions.push(tagParams);
134+
135+
return conversions;
136+
},
137+
[],
138+
mappedEvents
139+
);
140+
141+
// Fire each tag
142+
each(function(tagParams) {
143+
if (tagParams._type === 'sales') return self.load('sales', tagParams);
144+
return self.load('counter', tagParams);
145+
}, tags);
146+
};
147+
148+
/**
149+
* Page
150+
* Fire Floodlight image tags per Segment event
151+
*
152+
* https://support.google.com/dcm/partner/answer/2823425?hl=en&ref_topic=4241548
153+
* https://support.google.com/dcm/partner/answer/2823363
154+
* @api public
155+
* @param {Page}
156+
*/
157+
158+
Floodlight.prototype.page = function(page) {
159+
var name = page.fullName();
160+
161+
if (name) this.track(page.track(name));
162+
};

Diff for: integrations/doubleclick-floodlight/package.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@segment/analytics.js-integration-doubleclick-floodlight",
3+
"description": "The DoubleClick Floodlight analytics.js integration.",
4+
"version": "1.4.2",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"doubleclick-floodlight",
10+
"doubleclick",
11+
"floodlight"
12+
],
13+
"main": "lib/index.js",
14+
"scripts": {
15+
"test": "karma start",
16+
"test:ci": "karma start karma.conf-ci.js"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/segmentio/analytics.js-integrations.git"
21+
},
22+
"author": "Segment <[email protected]>",
23+
"license": "SEE LICENSE IN LICENSE",
24+
"bugs": {
25+
"url": "https://github.com/segmentio/analytics.js-integrations/issues"
26+
},
27+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/doubleclick-floodlight#readme",
28+
"dependencies": {
29+
"@ndhoule/each": "^2.0.1",
30+
"@ndhoule/foldl": "^2.0.1",
31+
"@segment/analytics.js-integration": "^3.2.0",
32+
"component-querystring": "^2.0.0",
33+
"obj-case": "^0.2.0",
34+
"to-no-case": "^0.1.3"
35+
},
36+
"devDependencies": {
37+
"@segment/analytics.js-core": "^3.8.2",
38+
"@segment/analytics.js-integration-tester": "^3.1.1",
39+
"@segment/clear-env": "^2.1.1",
40+
"browserify": "^16.2.3",
41+
"eslint": "^5.16.0",
42+
"karma": "^4.1.0",
43+
"karma-browserify": "^6.0.0",
44+
"karma-chrome-launcher": "^2.2.0",
45+
"karma-mocha": "^1.3.0",
46+
"karma-mocha-reporter": "^2.2.5",
47+
"karma-sauce-launcher": "^2.0.2",
48+
"karma-spec-reporter": "^0.0.32",
49+
"karma-summary-reporter": "^1.6.0",
50+
"mocha": "^6.1.4",
51+
"watchify": "^3.11.1",
52+
"sinon": "^1.17.6"
53+
}
54+
}

0 commit comments

Comments
 (0)