Skip to content

Commit b3dcc4d

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

File tree

6 files changed

+323
-0
lines changed

6 files changed

+323
-0
lines changed

integrations/improvely/HISTORY.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2.0.1 / 2016-06-21
2+
==================
3+
4+
* Fix test failures on page unload
5+
6+
2.0.0 / 2016-06-21
7+
==================
8+
9+
* Remove Duo compatibility
10+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
11+
* Update eslint configuration
12+
13+
1.0.4 / 2016-05-07
14+
==================
15+
16+
* Bump Analytics.js core, tester, integration to use Facade 2.x
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/improvely/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# analytics.js-integration-improvely [![Build Status][ci-badge]][ci-link]
2+
3+
Improvely 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-improvely
12+
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-improvely.svg?style=svg
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
9+
/**
10+
* Expose `Improvely` integration.
11+
*/
12+
13+
var Improvely = module.exports = integration('Improvely')
14+
.assumesPageview()
15+
.global('_improvely')
16+
.global('improvely')
17+
.option('domain', '')
18+
.option('projectId', null)
19+
.tag('<script src="//{{ domain }}.iljmp.com/improvely.js">');
20+
21+
/**
22+
* Initialize.
23+
*
24+
* http://www.improvely.com/docs/landing-page-code
25+
*
26+
* @api public
27+
*/
28+
29+
Improvely.prototype.initialize = function() {
30+
// Shim out the Improvely library/globals.
31+
window._improvely = [];
32+
/* eslint-disable */
33+
window.improvely = { init: function(e, t){ window._improvely.push(["init", e, t]); }, goal: function(e){ window._improvely.push(["goal", e]); }, label: function(e){ window._improvely.push(["label", e]); }};
34+
/* eslint-enable */
35+
36+
var domain = this.options.domain;
37+
var id = this.options.projectId;
38+
window.improvely.init(domain, id);
39+
this.load(this.ready);
40+
};
41+
42+
/**
43+
* Loaded?
44+
*
45+
* @api private
46+
* @return {boolean}
47+
*/
48+
49+
Improvely.prototype.loaded = function() {
50+
return !!(window.improvely && window.improvely.identify);
51+
};
52+
53+
/**
54+
* Identify.
55+
*
56+
* http://www.improvely.com/docs/labeling-visitors
57+
*
58+
* @api public
59+
* @param {Identify} identify
60+
*/
61+
62+
Improvely.prototype.identify = function(identify) {
63+
var id = identify.userId();
64+
if (id) window.improvely.label(id);
65+
};
66+
67+
/**
68+
* Track.
69+
*
70+
* http://www.improvely.com/docs/conversion-code
71+
*
72+
* @api public
73+
* @param {Track} track
74+
*/
75+
76+
Improvely.prototype.track = function(track) {
77+
var props = track.properties({ revenue: 'amount' });
78+
props.type = track.event();
79+
window.improvely.goal(props);
80+
};
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-improvely",
3+
"description": "The Improvely analytics.js integration.",
4+
"version": "2.0.1",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"improvely"
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/improvely#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: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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 Improvely = require('../lib/');
8+
9+
describe('Improvely', function() {
10+
var analytics;
11+
var improvely;
12+
var options = {
13+
domain: 'demo',
14+
projectId: 1
15+
};
16+
17+
beforeEach(function() {
18+
analytics = new Analytics();
19+
improvely = new Improvely(options);
20+
analytics.use(Improvely);
21+
analytics.use(tester);
22+
analytics.add(improvely);
23+
});
24+
25+
afterEach(function() {
26+
analytics.restore();
27+
analytics.reset();
28+
improvely.reset();
29+
sandbox();
30+
});
31+
32+
// FIXME(ndhoule): This block of code prevents post-test errors. Test cleanup
33+
// should be fixed to render this unnecessary
34+
after(function() {
35+
window.improvely = {
36+
identify: function() {}
37+
};
38+
});
39+
40+
it('should have the right settings', function() {
41+
analytics.compare(Improvely, integration('Improvely')
42+
.assumesPageview()
43+
.global('_improvely')
44+
.global('improvely')
45+
.option('domain', '')
46+
.option('projectId', null));
47+
});
48+
49+
describe('before loading', function() {
50+
beforeEach(function() {
51+
analytics.stub(improvely, 'load');
52+
});
53+
54+
describe('#initialize', function() {
55+
it('should create window._improvely', function() {
56+
analytics.assert(!window._improvely);
57+
analytics.initialize();
58+
analytics.page();
59+
analytics.assert(window._improvely instanceof Array);
60+
});
61+
62+
it('should create window.improvely', function() {
63+
analytics.assert(!window.improvely);
64+
analytics.initialize();
65+
analytics.page();
66+
analytics.assert(window.improvely);
67+
});
68+
69+
it('should init with a domain and project id', function() {
70+
analytics.initialize();
71+
analytics.page();
72+
analytics.deepEqual(window._improvely[0], ['init', options.domain, options.projectId]);
73+
});
74+
75+
it('should call #load', function() {
76+
analytics.initialize();
77+
analytics.page();
78+
analytics.called(improvely.load);
79+
});
80+
});
81+
});
82+
83+
describe('loading', function() {
84+
it('should load', function(done) {
85+
analytics.load(improvely, done);
86+
});
87+
});
88+
89+
describe('after loading', function() {
90+
beforeEach(function(done) {
91+
analytics.once('ready', done);
92+
analytics.initialize();
93+
analytics.page();
94+
});
95+
96+
describe('#identify', function() {
97+
beforeEach(function() {
98+
analytics.stub(window.improvely, 'label');
99+
});
100+
101+
it('should send an id', function() {
102+
analytics.identify('id');
103+
analytics.called(window.improvely.label, 'id');
104+
});
105+
106+
it('should not send if id is empty', function() {
107+
analytics.identify();
108+
analytics.didNotCall(window.improvely.label);
109+
});
110+
});
111+
112+
describe('#track', function() {
113+
beforeEach(function() {
114+
analytics.stub(window.improvely, 'goal');
115+
});
116+
117+
it('should send an event', function() {
118+
analytics.track('event');
119+
analytics.called(window.improvely.goal, { type: 'event' });
120+
});
121+
122+
it('should send an event and properties', function() {
123+
analytics.track('event', { property: true });
124+
analytics.called(window.improvely.goal, {
125+
type: 'event',
126+
property: true
127+
});
128+
});
129+
130+
it('should alias revenue to amount', function() {
131+
analytics.track('event', { revenue: 42.99 });
132+
analytics.called(window.improvely.goal, {
133+
type: 'event',
134+
amount: 42.99
135+
});
136+
});
137+
});
138+
});
139+
});

0 commit comments

Comments
 (0)