Skip to content

Commit 17d849e

Browse files
Add integration autosend This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-autosend Readme: https://github.com/segment-integrations/analytics.js-integration-autosend/blob/master/README.md
1 parent 2dd46f7 commit 17d849e

File tree

6 files changed

+281
-0
lines changed

6 files changed

+281
-0
lines changed

integrations/autosend/HISTORY.md

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:

integrations/autosend/README.md

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

integrations/autosend/lib/index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
9+
/**
10+
* Expose `Autosend` integration.
11+
*/
12+
13+
var Autosend = module.exports = integration('Autosend')
14+
.global('_autosend')
15+
.option('appKey', '')
16+
.tag('<script id="asnd-tracker" src="https://d2zjxodm1cz8d6.cloudfront.net/js/v1/autosend.js" data-auth-key="{{ appKey }}">');
17+
18+
/**
19+
* Initialize.
20+
*
21+
* http://autosend.io/faq/install-autosend-using-javascript/
22+
*
23+
* @api public
24+
*/
25+
26+
Autosend.prototype.initialize = function() {
27+
window._autosend = window._autosend || [];
28+
/* eslint-disable */
29+
(function(){var a,b,c;a=function(f){return function(){window._autosend.push([f].concat(Array.prototype.slice.call(arguments,0))); }; }; b=["identify", "track", "cb"];for (c=0;c<b.length;c++){window._autosend[b[c]]=a(b[c]); } })();
30+
/* eslint-enable */
31+
this.load(this.ready);
32+
};
33+
34+
/**
35+
* Loaded?
36+
*
37+
* @api private
38+
* @return {boolean}
39+
*/
40+
41+
Autosend.prototype.loaded = function() {
42+
return !!window._autosend;
43+
};
44+
45+
/**
46+
* Identify.
47+
*
48+
* http://autosend.io/faq/install-autosend-using-javascript/
49+
*
50+
* @api public
51+
* @param {Identify} identify
52+
*/
53+
54+
Autosend.prototype.identify = function(identify) {
55+
var id = identify.userId();
56+
if (!id) return;
57+
58+
var traits = identify.traits();
59+
traits.id = id;
60+
window._autosend.identify(traits);
61+
};
62+
63+
/**
64+
* Track.
65+
*
66+
* http://autosend.io/faq/install-autosend-using-javascript/
67+
*
68+
* @api public
69+
* @param {Track} track
70+
*/
71+
72+
Autosend.prototype.track = function(track) {
73+
window._autosend.track(track.event());
74+
};

integrations/autosend/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@segment/analytics.js-integration-autosend",
3+
"description": "The Autosend analytics.js integration.",
4+
"version": "2.0.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"autosend"
10+
],
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "make test"
14+
},
15+
"author": "Segment \u003cfriends@segment.com\u003e",
16+
"license": "SEE LICENSE IN LICENSE",
17+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/autosend#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+
"@segment/analytics.js-integration": "^2.1.0"
27+
},
28+
"devDependencies": {
29+
"@segment/analytics.js-core": "^3.0.0",
30+
"@segment/analytics.js-integration-tester": "^3.1.0",
31+
"@segment/clear-env": "^2.0.0",
32+
"@segment/eslint-config": "^3.1.1",
33+
"browserify": "^13.0.0",
34+
"browserify-istanbul": "^2.0.0",
35+
"eslint": "^2.9.0",
36+
"eslint-plugin-mocha": "^2.2.0",
37+
"eslint-plugin-require-path-exists": "^1.1.5",
38+
"istanbul": "^0.4.3",
39+
"karma": "1.3.0",
40+
"karma-browserify": "^5.0.4",
41+
"karma-chrome-launcher": "^1.0.1",
42+
"karma-coverage": "^1.0.0",
43+
"karma-junit-reporter": "^1.0.0",
44+
"karma-mocha": "1.0.1",
45+
"karma-phantomjs-launcher": "^1.0.0",
46+
"karma-sauce-launcher": "^1.0.0",
47+
"karma-spec-reporter": "0.0.26",
48+
"mocha": "^2.2.5",
49+
"npm-check": "^5.2.1",
50+
"phantomjs-prebuilt": "^2.1.7",
51+
"watchify": "^3.7.0"
52+
}
53+
}
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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
'use strict';
2+
3+
var Analytics = require('@segment/analytics.js-core').constructor;
4+
var integration = require('@segment/analytics.js-integration');
5+
var sandbox = require('@segment/clear-env');
6+
var tester = require('@segment/analytics.js-integration-tester');
7+
var Autosend = require('../lib/');
8+
9+
describe('Autosend', function() {
10+
var analytics;
11+
var autosend;
12+
var options = {
13+
appKey: '7677b3b8a09744c9ba8bcef3fac82fe2'
14+
};
15+
16+
beforeEach(function() {
17+
analytics = new Analytics();
18+
autosend = new Autosend(options);
19+
analytics.use(Autosend);
20+
analytics.use(tester);
21+
analytics.add(autosend);
22+
});
23+
24+
afterEach(function() {
25+
analytics.restore();
26+
analytics.reset();
27+
autosend.reset();
28+
sandbox();
29+
});
30+
31+
it('should have the right settings', function() {
32+
analytics.compare(Autosend, integration('Autosend')
33+
.global('_autosend')
34+
.option('appKey', ''));
35+
});
36+
37+
describe('before loading', function() {
38+
beforeEach(function() {
39+
analytics.stub(autosend, 'load');
40+
});
41+
42+
describe('#initialize', function() {
43+
it('should create window._autosend object', function() {
44+
analytics.assert(!window._autosend);
45+
analytics.initialize();
46+
analytics.page();
47+
analytics.assert(window._autosend);
48+
});
49+
50+
it('should call #load', function() {
51+
analytics.initialize();
52+
analytics.page();
53+
analytics.called(autosend.load);
54+
});
55+
});
56+
});
57+
58+
describe('loading', function() {
59+
it('should load', function(done) {
60+
analytics.load(autosend, done);
61+
});
62+
});
63+
64+
describe('after loading', function() {
65+
beforeEach(function(done) {
66+
analytics.once('ready', done);
67+
analytics.initialize();
68+
analytics.page();
69+
});
70+
71+
describe('#identify', function() {
72+
beforeEach(function() {
73+
analytics.stub(window._autosend, 'identify');
74+
});
75+
76+
it('should send an id', function() {
77+
analytics.identify('id');
78+
analytics.called(window._autosend.identify, { id: 'id' });
79+
});
80+
81+
it('shouldnt send without an id', function() {
82+
analytics.identify({ trait: true });
83+
analytics.didNotCall(window._autosend.identify);
84+
});
85+
86+
it('should send an id and traits', function() {
87+
analytics.identify('id', { trait: true });
88+
analytics.called(window._autosend.identify, { id: 'id', trait: true });
89+
});
90+
});
91+
92+
describe('#track', function() {
93+
beforeEach(function() {
94+
analytics.stub(window._autosend, 'track');
95+
});
96+
97+
it('should send an event', function() {
98+
analytics.track('event');
99+
analytics.called(window._autosend.track, 'event');
100+
});
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)