Skip to content

[PLATFORM-2895] Part 1: Migrate integrations #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 12, 2018
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
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ jobs:
- attach_workspace: { at: . }
- restore_cache:
key: deps-{{ checksum "yarn.lock" }}
- run:
name: Linter
command: yarn lint
- run:
name: Test updated integrations in PhantomJS
command: yarn test-integrations --browsers PhantomJS
Expand Down
3 changes: 2 additions & 1 deletion MIGRATE-INTEGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ and pull requests.
the repository:
- `$ bin/boneyard-integration-repository --integration <integration name>`


NOTE: For big migrations, it's ok to skip SauceLabs tests, but make sure
local tests work (PhantomJS).
53 changes: 53 additions & 0 deletions integrations/convertro/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

2.1.2 / 2016-08-16
==================

* npm publish

2.1.1 / 2016-08-16
==================

* Merge pull request #7 from segment-integrations/update/ajs-integration
* updating dependencies

2.1.0 / 2016-08-16
==================

* Merge pull request #5 from segment-integrations/update/ecommerce-spec-v2
* update ecommerce spec syntax to v2
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/convertro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# analytics.js-integration-convertro [![Build Status][ci-badge]][ci-link]

Convertro integration for [Analytics.js][].

## License

Released under the [MIT license](LICENSE).


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

/**
* Module dependencies.
*/

var each = require('@ndhoule/each');
var integration = require('@segment/analytics.js-integration');
var push = require('global-queue')('$CVO');

/**
* Expose `Convertro` integration.
*/

var Convertro = module.exports = integration('Convertro')
.global('$CVO')
.global('__cvo')
.option('account', '')
.option('hybridAttributionModel', false)
.mapping('events')
.tag('<script src="//d1ivexoxmp59q7.cloudfront.net/{{ account }}/live.js">');

/**
* Initialize.
*/

Convertro.prototype.initialize = function() {
this.load(this.ready);
};

/**
* Loaded?
*
* @api public
* @return {boolean}
*/

Convertro.prototype.loaded = function() {
return typeof (window.$CVO && window.$CVO.trackEvent) === 'function';
};

/**
* Identify.
*
* @api public
* @param {Facade} identify
*/

Convertro.prototype.identify = function(identify) {
if (!identify.userId()) return;
push('trackUser', identify.traits());
};

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

Convertro.prototype.track = function(track) {
var events = this.events(track.event());
var revenue = track.revenue();
var total = track.total();
each(function(type) {
push('trackEvent', {
amount: total ? total : revenue,
id: track.orderId(),
type: type
});
}, events);
};

/**
* Order Completed & Attribution model
* - Convertro has two attribution models
* - the first is for when you don't know if clients are new/repeat
* - the second is for when you know if a client is new/repeat
* - The hybridAttributionModel allows users to
* - move between the two attribution models
*
* - option=hybridAttributionModel (true)
* - type="sale" && "sale.new"(.repeat=false), when it's a new order.
* - type="sale" && "sale.repeat"(.repeat=true), when it's repeat order
* - type="sale" (.repeat=null), when you can't figure out if an order is repeat / new
*
* - option=hybridAttributionModel (false)
* - type="sale.new"(.repeat=false), when it's a new order.
* - type="sale.repeat"(.repeat=true), when it's repeat order.
* - type="sale" (.repeat=null), when you can't figure out if an order is repeat / new
*
*
* @api public
* @param {Track} track
*/

Convertro.prototype.orderCompleted = function(track) {
var repeat = track.proxy('properties.repeat');
var amount = track.total() || track.revenue();
var id = track.orderId();

if (typeof repeat === 'boolean') {
push('trackEvent', {
id: id,
type: repeat ? 'sale.repeat' : 'sale.new',
amount: amount
});
}

if (typeof repeat !== 'boolean' || this.options.hybridAttributionModel) {
push('trackEvent', {
id: id,
type: 'sale',
amount: amount
});
}
};
55 changes: 55 additions & 0 deletions integrations/convertro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@segment/analytics.js-integration-convertro",
"description": "The Convertro analytics.js integration.",
"version": "2.1.2",
"keywords": [
"analytics.js",
"analytics.js-integration",
"segment",
"convertro"
],
"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/convertro#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": "^3.1.0",
"global-queue": "^1.0.1"
},
"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/convertro/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@segment/eslint-config/mocha"
}
Loading