Skip to content

Commit 838338b

Browse files
authored
Migrate Adlearn Open Platform (#28)
* Add integration adlearn-open-platform This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-adlearn-open-platform Readme: https://github.com/segment-integrations/analytics.js-integration-adlearn-open-platform/blob/master/README.md * Add instructions
1 parent b85facf commit 838338b

File tree

11 files changed

+5647
-9
lines changed

11 files changed

+5647
-9
lines changed

MIGRATE-INTEGRATIONS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# HOW TO MIGRATE AN AJS INTEGRATION TO THE MONOREPO
2+
3+
We are in the process of migrating all analytics-js integrations into
4+
this monorepo. These are the steps to follow to ensure we don't break
5+
people's stuff.
6+
7+
1. Make sure your environment is set up:
8+
- Github credentials (see [README](operations/README.md))
9+
- The latest build of operations
10+
11+
2. Copy the integrations file into the monorepo with `migrate-integration`:
12+
- `$ goto analytics.js-integrations`
13+
- `$ bin/migrate-integration --integration <integration name>`
14+
This step also updates the original repository, migrating the issues
15+
and pull requests.
16+
17+
3. Submit the pull request and merge the changes.
18+
4. Archive original repository:
19+
- `$ bin/archive-integration-repository --integration <integration name>`
20+
5. When all original pull requests and issues have been addressed, "boneyard"
21+
the repository:
22+
- `$ bin/boneyard-integration-repository --integration <integration name>`
23+
24+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2.0.0 / 2016-06-21
2+
==================
3+
4+
* Remove Duo compatibility
5+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
6+
* Update eslint configuration
7+
8+
1.0.5 / 2016-05-07
9+
==================
10+
11+
* Bump Analytics.js core, tester, integration to use Facade 2.x
12+
13+
1.0.4 / 2015-06-30
14+
==================
15+
16+
* Replace analytics.js dependency with analytics.js-core
17+
18+
1.0.3 / 2015-06-30
19+
==================
20+
21+
* Replace analytics.js dependency with analytics.js-core
22+
23+
1.0.2 / 2015-06-24
24+
==================
25+
26+
* Bump analytics.js-integration version
27+
28+
1.0.1 / 2015-06-24
29+
==================
30+
31+
* Bump analytics.js-integration version
32+
33+
1.0.0 / 2015-06-09
34+
==================
35+
36+
* 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-adlearn-open-platform [![Build Status][ci-badge]][ci-link]
2+
3+
Adlearn Open Platform integration for [Analytics.js][].
4+
5+
## License
6+
7+
Released under the [MIT license](License.md).
8+
9+
10+
[Analytics.js]: https://segment.com/docs/libraries/analytics.js/
11+
[ci-link]: https://ci.segment.com/gh/segment-integrations/analytics.js-integration-adlearn-open-platform
12+
[ci-badge]: https://ci.segment.com/gh/segment-integrations/analytics.js-integration-adlearn-open-platform.svg?style=svg&circle-token=b8a9d9117d4dd82c72334dcfd98e02b3a810b783
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
/*
4+
* Module dependencies.
5+
*/
6+
7+
var each = require('@ndhoule/each');
8+
var integration = require('@segment/analytics.js-integration');
9+
10+
/**
11+
* Define the `AdlearnOpenPlatform` integration.
12+
*/
13+
var AdLearnOpenPlatform = integration('AdLearn Open Platform')
14+
.option('retargetingPixelId', '')
15+
.tag('retargeting', '<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr={{ retargetingPixelId }}"/>')
16+
.tag('existingUsers', '<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&srvc=1&betr={{ retargetingPixelId }}=920204[720]"/>')
17+
.tag('conversion', '<img src="https://secure.ace-tag.advertising.com/action/type={{ type }}/bins=1/rich=0/mnum=1516/logs=0/xsstr1={{ userId }}/xsstr2={{ productIds }}/xssale={{ total }}/xsmemid={{ orderId }}/"/>')
18+
.mapping('events');
19+
20+
/**
21+
* Page load the retargeting pixel.
22+
*
23+
* @api public
24+
* @param {Page} page
25+
*/
26+
AdLearnOpenPlatform.prototype.page = function() {
27+
var user = this.analytics.user();
28+
29+
this.load('retargeting');
30+
if (user.id()) this.load('existingUsers');
31+
};
32+
33+
/**
34+
* Track conversion events.
35+
*
36+
* @api public
37+
* @param {Track} track
38+
*/
39+
AdLearnOpenPlatform.prototype.track = function(track) {
40+
var userId = this.analytics.user().id();
41+
var orderId = track.orderId();
42+
var total = track.total() && (track.total() || 0).toFixed(2);
43+
var productIds = this.productIds(track.products());
44+
45+
var events = this.events(track.event());
46+
var self = this;
47+
each(function(event) {
48+
return self.load('conversion', {
49+
type: event,
50+
userId: userId || '',
51+
orderId: orderId || '',
52+
total: total || '',
53+
productIds: productIds || ''
54+
});
55+
}, events);
56+
};
57+
58+
/**
59+
* Join all the product IDs together for AdLearnOpenPlatform.
60+
*
61+
* @api private
62+
* @param {Object[]} products
63+
* @return {string}
64+
*/
65+
AdLearnOpenPlatform.prototype.productIds = function(products) {
66+
// TODO(ndhoule): Refactor into pluck(products, 'id')
67+
var ids = [];
68+
each(function(product) {
69+
ids.push(product.id);
70+
}, products);
71+
return ids.join(',');
72+
};
73+
74+
/*
75+
* Exports.
76+
*/
77+
78+
module.exports = AdLearnOpenPlatform;
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-adlearn-open-platform",
3+
"Description": "The Adlearn Open Platform analytics.js integration.",
4+
"Version": "2.0.0",
5+
"Keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"adlearn"
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/adlearn-open-platform#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.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": "^1.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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>integrations tests</title>
5+
<link rel="stylesheet" href="/node_modules/mocha/mocha.css">
6+
</head>
7+
<body>
8+
<div id="mocha"></div>
9+
<script src="/saucelabs.js"></script>
10+
<script src="/node_modules/mocha/mocha.js"></script>
11+
<script>
12+
mocha.setup({
13+
ui: 'bdd',
14+
ignoreLeaks: true,
15+
slow: 300,
16+
timeout: 10000
17+
});
18+
19+
var _onload = window.onload;
20+
window.onload = function() {
21+
if (typeof _onload === 'function') {
22+
_onload.apply(this, arguments);
23+
}
24+
25+
if (window.mochaPhantomJS) {
26+
mochaPhantomJS.run();
27+
} else if (window.saucelabs) {
28+
saucelabs(mocha.run());
29+
} else {
30+
mocha.run();
31+
}
32+
};
33+
</script>
34+
<script src="/build.js"></script>
35+
</body>
36+
</html>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
'use strict';
2+
3+
var AdLearnOpenPlatform = require('../lib');
4+
var Analytics = require('@segment/analytics.js-core').constructor;
5+
var integration = require('@segment/analytics.js-integration');
6+
var sandbox = require('@segment/clear-env');
7+
var tester = require('@segment/analytics.js-integration-tester');
8+
9+
describe('AdLearn Open Platform', function() {
10+
var adLearnOpenPlatform;
11+
var analytics;
12+
var options = {
13+
retargetingPixelId: '1234',
14+
events: {
15+
conversion: 1989,
16+
'completed order': 1979
17+
}
18+
};
19+
20+
beforeEach(function() {
21+
analytics = new Analytics();
22+
adLearnOpenPlatform = new AdLearnOpenPlatform(options);
23+
analytics.use(AdLearnOpenPlatform);
24+
analytics.use(tester);
25+
analytics.add(adLearnOpenPlatform);
26+
});
27+
28+
afterEach(function() {
29+
analytics.restore();
30+
analytics.reset();
31+
adLearnOpenPlatform.reset();
32+
sandbox();
33+
});
34+
35+
it('should have the right settings', function() {
36+
analytics.compare(AdLearnOpenPlatform, integration('AdLearn Open Platform')
37+
.option('retargetingPixelId', '')
38+
.mapping('events'));
39+
});
40+
41+
describe('after loading', function() {
42+
beforeEach(function(done) {
43+
analytics.once('ready', done);
44+
analytics.initialize();
45+
analytics.page();
46+
});
47+
48+
describe('#page', function() {
49+
beforeEach(function() {
50+
analytics.spy(adLearnOpenPlatform, 'load');
51+
});
52+
53+
it('should always trigger the retargeting pixel', function() {
54+
analytics.page();
55+
analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr=1234"/>');
56+
});
57+
58+
it('should trigger the pixel if there is an existing user', function() {
59+
analytics.identify('userId');
60+
analytics.page();
61+
analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr=1234"/>');
62+
analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&srvc=1&betr=1234=920204[720]"/>');
63+
});
64+
});
65+
66+
describe('#track', function() {
67+
beforeEach(function() {
68+
analytics.spy(adLearnOpenPlatform, 'load');
69+
});
70+
71+
it('should not track unmapped events', function() {
72+
analytics.track('event');
73+
analytics.didNotCall(adLearnOpenPlatform.load);
74+
});
75+
76+
describe('mapped events', function() {
77+
it('should track basic conversion with type', function() {
78+
analytics.track('conversion');
79+
analytics.loaded('<img src="https://secure.ace-tag.advertising.com/action/type=1989/bins=1/rich=0/mnum=1516/logs=0/xsstr1=/xsstr2=/xssale=/xsmemid=/"/>');
80+
});
81+
82+
it('should track basic conversion with type and user ID', function() {
83+
analytics.identify('userId');
84+
analytics.track('conversion');
85+
analytics.loaded('<img src="https://secure.ace-tag.advertising.com/action/type=1989/bins=1/rich=0/mnum=1516/logs=0/xsstr1=userId/xsstr2=/xssale=/xsmemid=/"/>');
86+
});
87+
88+
it('should track basic conversion with type, user ID, and ecommerce info', function() {
89+
analytics.identify('userId');
90+
analytics.track('completed order', {
91+
orderId: 'asdf',
92+
total: 123,
93+
products: [
94+
{
95+
id: '507f1f77bcf86cd799439011',
96+
sku: '45790-32',
97+
name: 'Monopoly: 3rd Edition',
98+
price: 19,
99+
quantity: 1,
100+
category: 'Games'
101+
},
102+
{
103+
id: '505bd76785ebb509fc183733',
104+
sku: '46493-32',
105+
name: 'Uno Card Game',
106+
price: 3,
107+
quantity: 2,
108+
category: 'Games'
109+
}
110+
]
111+
});
112+
analytics.loaded('<img src="https://secure.ace-tag.advertising.com/action/type=1979/bins=1/rich=0/mnum=1516/logs=0/xsstr1=userId/xsstr2=507f1f77bcf86cd799439011,505bd76785ebb509fc183733/xssale=123.00/xsmemid=asdf/"/>');
113+
});
114+
});
115+
});
116+
});
117+
});

0 commit comments

Comments
 (0)