Skip to content

Commit 86df711

Browse files
Add integration outbound This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-outbound Readme: https://github.com/segment-integrations/analytics.js-integration-outbound/blob/master/README.md
1 parent 81846a3 commit 86df711

File tree

6 files changed

+490
-0
lines changed

6 files changed

+490
-0
lines changed

integrations/outbound/HISTORY.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
2.1.0 / 2016-08-11
3+
==================
4+
5+
* segment io <> outbound for page calls (#6)
6+
* Stop window.outbound from leaking across test runs
7+
* Move Sauce Labs credentials into circle.yml
8+
* Update Karma to 1.1.0
9+
10+
2.0.0 / 2016-06-21
11+
==================
12+
13+
* Remove Duo compatibility
14+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
15+
* Update eslint configuration
16+
17+
1.0.6 / 2016-05-07
18+
==================
19+
20+
* Bump Analytics.js core, tester, integration to use Facade 2.x
21+
22+
1.0.5 / 2015-08-26
23+
==================
24+
25+
* Always identify before tracking an event
26+
27+
1.0.4 / 2015-07-30
28+
==================
29+
30+
* update trait handling to omit all cases of special traits from attributes
31+
32+
1.0.3 / 2015-06-30
33+
==================
34+
35+
* Replace analytics.js dependency with analytics.js-core
36+
37+
1.0.2 / 2015-06-24
38+
==================
39+
40+
* Bump analytics.js-integration version
41+
42+
1.0.1 / 2015-06-24
43+
==================
44+
45+
* Bump analytics.js-integration version
46+
47+
1.0.0 / 2015-06-09
48+
==================
49+
50+
* Initial commit :sparkles:

integrations/outbound/README.md

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

integrations/outbound/lib/index.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
2+
'use strict';
3+
4+
/**
5+
* Module dependencies.
6+
*/
7+
8+
var integration = require('@segment/analytics.js-integration');
9+
var uncase = require('to-no-case');
10+
var foldl = require('@ndhoule/foldl');
11+
var Identify = require('segmentio-facade').Identify;
12+
13+
/**
14+
* Expose `Outbound` integration.
15+
*/
16+
17+
var Outbound = module.exports = integration('Outbound')
18+
.global('outbound')
19+
.option('publicApiKey', '')
20+
.option('trackReferrer', false)
21+
.tag('<script src="//cdn.outbound.io/{{ publicApiKey }}.js">');
22+
23+
/**
24+
* Initialize.
25+
*
26+
* @api public
27+
*/
28+
29+
Outbound.prototype.initialize = function() {
30+
window.outbound = window.outbound || [];
31+
window.outbound.methods = [
32+
'identify',
33+
'track',
34+
'alias',
35+
'registerApnsToken',
36+
'registerGcmToken',
37+
'disableApnsToken',
38+
'disableGcmToken',
39+
'disableAllGcmTokens',
40+
'disableAllApnsTokens',
41+
'unsubscribeAll',
42+
'unsubscribeCampaigns',
43+
'subscribeAll',
44+
'subscribeCampaigns',
45+
'hasIdentified'
46+
];
47+
48+
window.outbound.factory = function(method) {
49+
return function() {
50+
var args = Array.prototype.slice.call(arguments);
51+
args.unshift(method);
52+
window.outbound.push(args);
53+
return window.outbound;
54+
};
55+
};
56+
57+
for (var i = 0; i < window.outbound.methods.length; i++) {
58+
var key = window.outbound.methods[i];
59+
window.outbound[key] = window.outbound.factory(key);
60+
}
61+
62+
this.load(this.ready);
63+
};
64+
65+
/**
66+
* Loaded
67+
*
68+
* @api private
69+
* @return {boolean}
70+
*/
71+
72+
Outbound.prototype.loaded = function() {
73+
return !!(window.outbound && window.outbound.reset);
74+
};
75+
76+
/**
77+
* Identify.
78+
*
79+
* @api public
80+
* @param {Identify} identify
81+
*/
82+
83+
Outbound.prototype.identify = function(identify) {
84+
var specialTraits = {
85+
id: true,
86+
email: true,
87+
phone: true,
88+
'user id': true,
89+
'last name': true,
90+
'first name': true
91+
};
92+
93+
var userId = identify.userId() || identify.anonymousId();
94+
95+
var attributes = foldl(function(acc, val, key) {
96+
if (!specialTraits.hasOwnProperty(uncase(key))) acc.attributes[key] = val;
97+
return acc;
98+
}, {
99+
attributes: {},
100+
email: identify.email(),
101+
phoneNumber: identify.phone(),
102+
firstName: identify.firstName(),
103+
lastName: identify.lastName()
104+
}, identify.traits());
105+
106+
window.outbound.identify(userId, attributes);
107+
};
108+
109+
/**
110+
* Track.
111+
*
112+
* @api public
113+
* @param {Track} track
114+
*/
115+
116+
Outbound.prototype.track = function(track) {
117+
if (!window.outbound.hasIdentified()) {
118+
var user = new Identify({ userId: track.userId() || track.anonymousId() });
119+
this.identify(user);
120+
}
121+
window.outbound.track(track.event(), track.properties(), track.timestamp());
122+
};
123+
124+
/**
125+
* Alias.
126+
*
127+
* @api public
128+
* @param {Alias} alias
129+
*/
130+
131+
Outbound.prototype.alias = function(alias) {
132+
window.outbound.identify(alias.userId(), { previousId: alias.previousId() });
133+
};
134+
135+
/**
136+
* Page.
137+
*
138+
* @api public
139+
* @param {Page} page
140+
*/
141+
Outbound.prototype.page = function(page) {
142+
var props = page.properties();
143+
var evtName = '[Segment Page]';
144+
145+
if (!this.options.trackReferrer) {
146+
delete props.referrer;
147+
}
148+
149+
if (props.name || props.url) {
150+
evtName += ' ' + props.name || props.url;
151+
}
152+
153+
if (!window.outbound.hasIdentified()) {
154+
var user = new Identify({ userId: page.userId() || page.anonymousId() });
155+
this.identify(user);
156+
}
157+
158+
window.outbound.track(evtName, props, page.timestamp());
159+
};

integrations/outbound/package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@segment/analytics.js-integration-outbound",
3+
"description": "The Outbound analytics.js integration.",
4+
"version": "2.1.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"outbound"
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/outbound#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/foldl": "^2.0.1",
27+
"@segment/analytics.js-integration": "^2.1.0",
28+
"segmentio-facade": "^3.0.3",
29+
"to-no-case": "^1.0.1"
30+
},
31+
"devDependencies": {
32+
"@segment/analytics.js-core": "^3.0.0",
33+
"@segment/analytics.js-integration-tester": "^3.1.0",
34+
"@segment/clear-env": "^2.0.0",
35+
"@segment/eslint-config": "^3.1.1",
36+
"browserify": "^13.0.0",
37+
"browserify-istanbul": "^2.0.0",
38+
"eslint": "^2.9.0",
39+
"eslint-plugin-mocha": "^2.2.0",
40+
"eslint-plugin-require-path-exists": "^1.1.5",
41+
"istanbul": "^0.4.3",
42+
"karma": "1.3.0",
43+
"karma-browserify": "^5.0.4",
44+
"karma-chrome-launcher": "^1.0.1",
45+
"karma-coverage": "^1.0.0",
46+
"karma-junit-reporter": "^1.0.0",
47+
"karma-mocha": "1.0.1",
48+
"karma-phantomjs-launcher": "^1.0.0",
49+
"karma-sauce-launcher": "^1.0.0",
50+
"karma-spec-reporter": "0.0.26",
51+
"mocha": "^2.2.5",
52+
"npm-check": "^5.2.1",
53+
"phantomjs-prebuilt": "^2.1.7",
54+
"watchify": "^3.7.0"
55+
}
56+
}
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+
}

0 commit comments

Comments
 (0)