Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions MIGRATE-INTEGRATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# HOW TO MIGRATE AN AJS INTEGRATION TO THE MONOREPO

We are in the process of migrating all analytics-js integrations into
this monorepo. These are the steps to follow to ensure we don't break
people's stuff.

1. Make sure your environment is set up:
- Github credentials (see [README](operations/README.md))
- The latest build of operations

2. Copy the integrations file into the monorepo with `migrate-integration`:
- `$ goto analytics.js-integrations`
- `$ bin/migrate-integration --integration <integration name>`
This step also updates the original repository, migrating the issues
and pull requests.

3. Submit the pull request and merge the changes.
4. Archive original repository:
- `$ bin/archive-integration-repository --integration <integration name>`
5. When all original pull requests and issues have been addressed, "boneyard"
the repository:
- `$ bin/boneyard-integration-repository --integration <integration name>`


36 changes: 36 additions & 0 deletions integrations/adlearn-open-platform/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
2.0.0 / 2016-06-21
==================

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

1.0.5 / 2016-05-07
==================

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

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/adlearn-open-platform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# analytics.js-integration-adlearn-open-platform [![Build Status][ci-badge]][ci-link]

Adlearn Open Platform integration for [Analytics.js][].

## License

Released under the [MIT license](License.md).


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

/*
* Module dependencies.
*/

var each = require('@ndhoule/each');
var integration = require('@segment/analytics.js-integration');

/**
* Define the `AdlearnOpenPlatform` integration.
*/
var AdLearnOpenPlatform = integration('AdLearn Open Platform')
.option('retargetingPixelId', '')
.tag('retargeting', '<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr={{ retargetingPixelId }}"/>')
.tag('existingUsers', '<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&srvc=1&betr={{ retargetingPixelId }}=920204[720]"/>')
.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 }}/"/>')
.mapping('events');

/**
* Page load the retargeting pixel.
*
* @api public
* @param {Page} page
*/
AdLearnOpenPlatform.prototype.page = function() {
var user = this.analytics.user();

this.load('retargeting');
if (user.id()) this.load('existingUsers');
};

/**
* Track conversion events.
*
* @api public
* @param {Track} track
*/
AdLearnOpenPlatform.prototype.track = function(track) {
var userId = this.analytics.user().id();
var orderId = track.orderId();
var total = track.total() && (track.total() || 0).toFixed(2);
var productIds = this.productIds(track.products());

var events = this.events(track.event());
var self = this;
each(function(event) {
return self.load('conversion', {
type: event,
userId: userId || '',
orderId: orderId || '',
total: total || '',
productIds: productIds || ''
});
}, events);
};

/**
* Join all the product IDs together for AdLearnOpenPlatform.
*
* @api private
* @param {Object[]} products
* @return {string}
*/
AdLearnOpenPlatform.prototype.productIds = function(products) {
// TODO(ndhoule): Refactor into pluck(products, 'id')
var ids = [];
each(function(product) {
ids.push(product.id);
}, products);
return ids.join(',');
};

/*
* Exports.
*/

module.exports = AdLearnOpenPlatform;
54 changes: 54 additions & 0 deletions integrations/adlearn-open-platform/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"Name": "@segment/analytics.js-integration-adlearn-open-platform",
"Description": "The Adlearn Open Platform analytics.js integration.",
"Version": "2.0.0",
"Keywords": [
"analytics.js",
"analytics.js-integration",
"segment",
"adlearn"
],
"Main": "lib/index.js",
"Scripts": {
"test": "make test"
},
"Author": "Segment \[email protected]\u003e",
"License": "SEE LICENSE IN LICENSE",
"Homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/adlearn-open-platform#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.0.1"
},
"DevDependencies": {
"@segment/analytics.js-core": "^3.0.0",
"@segment/analytics.js-integration-tester": "^3.1.0",
"@segment/clear-env": "^1.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/adlearn-open-platform/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@segment/eslint-config/mocha"
}
36 changes: 36 additions & 0 deletions integrations/adlearn-open-platform/test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>integrations tests</title>
<link rel="stylesheet" href="/node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="/saucelabs.js"></script>
<script src="/node_modules/mocha/mocha.js"></script>
<script>
mocha.setup({
ui: 'bdd',
ignoreLeaks: true,
slow: 300,
timeout: 10000
});

var _onload = window.onload;
window.onload = function() {
if (typeof _onload === 'function') {
_onload.apply(this, arguments);
}

if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else if (window.saucelabs) {
saucelabs(mocha.run());
} else {
mocha.run();
}
};
</script>
<script src="/build.js"></script>
</body>
</html>
117 changes: 117 additions & 0 deletions integrations/adlearn-open-platform/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
'use strict';

var AdLearnOpenPlatform = require('../lib');
var Analytics = require('@segment/analytics.js-core').constructor;
var integration = require('@segment/analytics.js-integration');
var sandbox = require('@segment/clear-env');
var tester = require('@segment/analytics.js-integration-tester');

describe('AdLearn Open Platform', function() {
var adLearnOpenPlatform;
var analytics;
var options = {
retargetingPixelId: '1234',
events: {
conversion: 1989,
'completed order': 1979
}
};

beforeEach(function() {
analytics = new Analytics();
adLearnOpenPlatform = new AdLearnOpenPlatform(options);
analytics.use(AdLearnOpenPlatform);
analytics.use(tester);
analytics.add(adLearnOpenPlatform);
});

afterEach(function() {
analytics.restore();
analytics.reset();
adLearnOpenPlatform.reset();
sandbox();
});

it('should have the right settings', function() {
analytics.compare(AdLearnOpenPlatform, integration('AdLearn Open Platform')
.option('retargetingPixelId', '')
.mapping('events'));
});

describe('after loading', function() {
beforeEach(function(done) {
analytics.once('ready', done);
analytics.initialize();
analytics.page();
});

describe('#page', function() {
beforeEach(function() {
analytics.spy(adLearnOpenPlatform, 'load');
});

it('should always trigger the retargeting pixel', function() {
analytics.page();
analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr=1234"/>');
});

it('should trigger the pixel if there is an existing user', function() {
analytics.identify('userId');
analytics.page();
analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr=1234"/>');
analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&srvc=1&betr=1234=920204[720]"/>');
});
});

describe('#track', function() {
beforeEach(function() {
analytics.spy(adLearnOpenPlatform, 'load');
});

it('should not track unmapped events', function() {
analytics.track('event');
analytics.didNotCall(adLearnOpenPlatform.load);
});

describe('mapped events', function() {
it('should track basic conversion with type', function() {
analytics.track('conversion');
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=/"/>');
});

it('should track basic conversion with type and user ID', function() {
analytics.identify('userId');
analytics.track('conversion');
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=/"/>');
});

it('should track basic conversion with type, user ID, and ecommerce info', function() {
analytics.identify('userId');
analytics.track('completed order', {
orderId: 'asdf',
total: 123,
products: [
{
id: '507f1f77bcf86cd799439011',
sku: '45790-32',
name: 'Monopoly: 3rd Edition',
price: 19,
quantity: 1,
category: 'Games'
},
{
id: '505bd76785ebb509fc183733',
sku: '46493-32',
name: 'Uno Card Game',
price: 3,
quantity: 2,
category: 'Games'
}
]
});
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/"/>');
});
});
});
});
});
Loading