-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-drip Readme: https://github.com/segment-integrations/analytics.js-integration-drip/blob/master/README.md
- Loading branch information
1 parent
bac9428
commit 7269285
Showing
6 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
2.2.1 / 2017-11-01 | ||
================== | ||
|
||
* Bug fix | ||
|
||
2.2.0 / 2017-10-09 | ||
================== | ||
|
||
* Support mapping subscribing users to default Drip Campaign ID or dynamically via code through `.identify()` calls | ||
|
||
2.1.2 / 2017-10-09 | ||
================== | ||
|
||
* replace spaces with underscores for identify traits as Drip does not support spaces | ||
|
||
2.1.1 / 2017-04-05 | ||
================== | ||
|
||
* replace spaces with underscores for track property names | ||
* fix bug with value being sent with floating point | ||
|
||
2.1.0 / 2016-12-20 | ||
================== | ||
|
||
* Bump analytics.js-integration to ^3.2.0 | ||
* Remove .assumePageview() flag | ||
|
||
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# analytics.js-integration-drip [![Build Status][ci-badge]][ci-link] | ||
|
||
Drip 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-drip | ||
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-drip.svg?style=svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var integration = require('@segment/analytics.js-integration'); | ||
var isObject = require('isobject'); | ||
var push = require('global-queue')('_dcq'); | ||
var each = require('@ndhoule/each'); | ||
var find = require('obj-case').find; | ||
|
||
/** | ||
* Expose `Drip` integration. | ||
*/ | ||
|
||
var Drip = module.exports = integration('Drip') | ||
.global('_dc') | ||
.global('_dcq') | ||
.global('_dcqi') | ||
.global('_dcs') | ||
.option('account', '') | ||
.tag('<script src="//tag.getdrip.com/{{ account }}.js">'); | ||
|
||
/** | ||
* Initialize. | ||
* | ||
* @api public | ||
*/ | ||
|
||
Drip.prototype.initialize = function() { | ||
window._dcq = window._dcq || []; | ||
window._dcs = window._dcs || {}; | ||
window._dcs.account = this.options.account; | ||
this.load(this.ready); | ||
}; | ||
|
||
/** | ||
* Loaded? | ||
* | ||
* @api private | ||
* @return {boolean} | ||
*/ | ||
|
||
Drip.prototype.loaded = function() { | ||
return isObject(window._dc); | ||
}; | ||
|
||
/** | ||
* Track. | ||
* | ||
* @api public | ||
* @param {Track} track | ||
*/ | ||
|
||
Drip.prototype.track = function(track) { | ||
var props = format(track.properties()); | ||
var cents = Math.round(track.revenue() * 100); | ||
if (cents) props.value = cents; | ||
|
||
// removes redundant data | ||
delete props.revenue; | ||
push('track', track.event(), props); | ||
}; | ||
|
||
/** | ||
* Identify. | ||
* | ||
* @api public | ||
* @param {Identify} identify | ||
*/ | ||
|
||
Drip.prototype.identify = function(identify) { | ||
// minimum required trait to identify a user in Drip | ||
if (!identify.email()) return; | ||
|
||
push('identify', format(identify.traits())); | ||
|
||
// default can be configured in your UI settings | ||
var dripCampaignId = find(identify.options(this.name), 'campaignId') || this.options.campaignId; | ||
|
||
// you can subscribe users to specific campaigns in Drip | ||
// https://www.getdrip.com/docs/js-api#subscribe | ||
if (dripCampaignId) push('subscribe', { campaign_id: dripCampaignId, fields: identify.traits() }); | ||
}; | ||
|
||
/** | ||
* Format | ||
* Replaces spaces with underscores | ||
* | ||
* @api public | ||
* @param {Object} obj | ||
* | ||
*/ | ||
|
||
function format(obj) { | ||
var ret = {}; | ||
each(function(value, key) { | ||
var formattedKey = key.replace(/\s/g, '_'); | ||
ret[formattedKey] = value; | ||
}, obj); | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "@segment/analytics.js-integration-drip", | ||
"description": "The Drip analytics.js integration.", | ||
"version": "2.2.1", | ||
"keywords": [ | ||
"analytics.js", | ||
"analytics.js-integration", | ||
"segment", | ||
"drip" | ||
], | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"author": "Segment \u003cfriends@segment.com\u003e", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/drip#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.2.0", | ||
"global-queue": "^1.0.1", | ||
"isobject": "^2.1.0", | ||
"obj-case": "^0.2.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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@segment/eslint-config/mocha" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
'use strict'; | ||
|
||
var Analytics = require('@segment/analytics.js-core').constructor; | ||
var integration = require('@segment/analytics.js-integration'); | ||
var tester = require('@segment/analytics.js-integration-tester'); | ||
var sandbox = require('@segment/clear-env'); | ||
var Drip = require('../lib/'); | ||
|
||
describe('Drip', function() { | ||
var analytics; | ||
var drip; | ||
var options = { | ||
account: '3826504', | ||
campaignId: '' | ||
}; | ||
|
||
beforeEach(function() { | ||
analytics = new Analytics(); | ||
drip = new Drip(options); | ||
analytics.use(Drip); | ||
analytics.use(tester); | ||
analytics.add(drip); | ||
}); | ||
|
||
afterEach(function() { | ||
analytics.restore(); | ||
analytics.reset(); | ||
drip.reset(); | ||
sandbox(); | ||
}); | ||
|
||
it('should have the right settings', function() { | ||
analytics.compare(Drip, integration('Drip') | ||
.global('_dc') | ||
.global('_dcq') | ||
.global('_dcqi') | ||
.global('_dcs') | ||
.option('account', '')); | ||
}); | ||
|
||
describe('before loading', function() { | ||
beforeEach(function() { | ||
analytics.stub(drip, 'load'); | ||
}); | ||
|
||
describe('#initialize', function() { | ||
it('should create window._dcq', function() { | ||
analytics.assert(!window._dcq); | ||
analytics.initialize(); | ||
analytics.page(); | ||
analytics.assert(window._dcq instanceof Array); | ||
}); | ||
|
||
it('should create window._dcs', function() { | ||
analytics.assert(!window._dcs); | ||
analytics.initialize(); | ||
analytics.page(); | ||
analytics.assert(window._dcs); | ||
analytics.assert(window._dcs.account === options.account); | ||
}); | ||
|
||
it('should call #load', function() { | ||
analytics.initialize(); | ||
analytics.page(); | ||
analytics.called(drip.load); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('loading', function() { | ||
it('should load', function(done) { | ||
analytics.load(drip, done); | ||
}); | ||
}); | ||
|
||
describe('after loading', function() { | ||
beforeEach(function(done) { | ||
analytics.once('ready', done); | ||
analytics.initialize(); | ||
analytics.page(); | ||
}); | ||
|
||
describe('#track', function() { | ||
beforeEach(function() { | ||
analytics.stub(window._dcq, 'push'); | ||
}); | ||
|
||
it('should send event as the action', function() { | ||
analytics.track('event'); | ||
analytics.called(window._dcq.push, ['track', 'event', {}]); | ||
}); | ||
|
||
it('should convert and alias revenue', function() { | ||
analytics.track('event', { revenue: '9.99' }); | ||
analytics.called(window._dcq.push, ['track', 'event', { value: 999 }]); | ||
}); | ||
|
||
it('should replace spaces with underscores in for property keys', function() { | ||
analytics.track('event', { 'ahoy mate there': 'howdy' }); | ||
analytics.called(window._dcq.push, ['track', 'event', { ahoy_mate_there: 'howdy' }]); | ||
}); | ||
}); | ||
|
||
describe('#identify', function() { | ||
beforeEach(function() { | ||
analytics.stub(window._dcq, 'push'); | ||
}); | ||
|
||
it('should send identify with traits', function() { | ||
var traits = { email: 'philz@philz.com', heyyou: 'know yourself' }; | ||
analytics.identify('id', traits); | ||
analytics.called(window._dcq.push, ['identify', { id: 'id', heyyou: 'know yourself', email: 'philz@philz.com' }]); | ||
}); | ||
|
||
it('should not send if email is not there', function() { | ||
analytics.identify('id', { trait: true }); | ||
analytics.didNotCall(window._dcq.push); | ||
}); | ||
|
||
it('should subscribe to campaignId if provided in the settings', function() { | ||
drip.options.campaignId = '83702741'; | ||
var traits = { email: 'philz@philz.com', heyyou: 'know yourself', id: 'id' }; | ||
analytics.identify('id', traits); | ||
analytics.deepEqual(window._dcq.push.args[1], [['subscribe', { campaign_id: drip.options.campaignId, fields: traits }]]); | ||
}); | ||
|
||
it('should let you override subscribing to campaignId if provided in integration specific settings', function() { | ||
drip.options.campaignId = '83702741'; | ||
var traits = { email: 'philz@philz.com', heyyou: 'know yourself', id: 'id' }; | ||
var intOptions = { Drip: { campaignId: '12345678' } }; | ||
analytics.identify('id', traits, intOptions); | ||
analytics.deepEqual(window._dcq.push.args[1], [['subscribe', { campaign_id: '12345678', fields: traits }]]); | ||
}); | ||
}); | ||
}); | ||
}); |