Skip to content

Commit 19c3c57

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

File tree

7 files changed

+374
-0
lines changed

7 files changed

+374
-0
lines changed

integrations/wishpond/HISTORY.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2.0.1 / 2016-07-21
2+
==================
3+
4+
* Update integration settings to match Segment metadata
5+
6+
2.0.0 / 2016-07-12
7+
==================
8+
9+
* Remove Duo compatibility
10+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
11+
* Update eslint configuration
12+
13+
1.0.1 / 2016-06-10
14+
==================
15+
16+
* Use facade to alias traits (identify.traits(traitAliases)) on identify, Thanks f2prateek.
17+
* Update Readme with examples.
18+
19+
1.0.0 / 2016-04-11
20+
==================
21+
22+
* Initial commit :sparkles:

integrations/wishpond/LICENSE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2015 Segment.io <friends@segment.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+

integrations/wishpond/README.md

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

integrations/wishpond/lib/index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
9+
/**
10+
* Expose `Wishpond` integration.
11+
*/
12+
13+
var Wishpond = module.exports = integration('Wishpond')
14+
.global('Wishpond')
15+
.option('siteId', '')
16+
.option('apiKey', '')
17+
.tag('<script id="wishpond-tracker" src="//cdn.wishpond.net/connect.js">');
18+
19+
/**
20+
* Initialize.
21+
*
22+
* http://developers.wishpond.com/#introduction
23+
*
24+
* @api public
25+
*/
26+
27+
Wishpond.prototype.initialize = function() {
28+
window.Wishpond = window.Wishpond || [];
29+
window.Wishpond.merchantId = this.options.siteId;
30+
window.Wishpond.writeKey = this.options.apiKey;
31+
/* eslint-disable */
32+
(function(){
33+
var a,b,c;
34+
a = function(f){return function(){window.Wishpond.push([f].concat(Array.prototype.slice.call(arguments,0)));};};
35+
b = ['identify', 'track'];
36+
for (c = 0; c < b.length; c++) {window.Wishpond[b[c]] = a(b[c]);}}
37+
)();
38+
/* eslint-enable */
39+
this.load(this.ready);
40+
};
41+
42+
/**
43+
* Loaded?
44+
*
45+
* @api private
46+
* @return {boolean}
47+
*/
48+
49+
Wishpond.prototype.loaded = function() {
50+
return !!window.Wishpond.Logger;
51+
};
52+
53+
/**
54+
* Identify.
55+
*
56+
* http://developers.wishpond.com/#identify
57+
*
58+
* @api public
59+
* @param {Identify} identify
60+
*/
61+
62+
Wishpond.prototype.identify = function(identify) {
63+
if (!identify.userId()) return this.debug('user id required');
64+
65+
window.Wishpond.Tracker.identify(identify.userId(), identify.traits({
66+
createdAt: 'created_at',
67+
updatedAt: 'updated_at',
68+
firstName: 'first_name',
69+
lastName: 'last_name',
70+
phoneNumber: 'phone_number',
71+
leadScore: 'lead_score'
72+
}));
73+
};
74+
75+
/**
76+
* Track.
77+
*
78+
* http://developers.wishpond.com/#tracking-events
79+
*
80+
* @api public
81+
* @param {Track} track
82+
*/
83+
84+
Wishpond.prototype.track = function(track) {
85+
window.Wishpond.Tracker.track(track.event(), track.properties());
86+
};

integrations/wishpond/package.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@segment/analytics.js-integration-wishpond",
3+
"description": "The Wishpond analytics.js integration.",
4+
"version": "2.0.1",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"wishpond"
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/wishpond#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/each": "^2.0.1",
27+
"@segment/analytics.js-integration": "^2.1.0"
28+
},
29+
"devDependencies": {
30+
"@segment/analytics.js-core": "^3.0.0",
31+
"@segment/analytics.js-integration-tester": "^2.0.0",
32+
"@segment/clear-env": "^2.0.0",
33+
"@segment/eslint-config": "^3.1.1",
34+
"browserify": "^13.0.0",
35+
"browserify-istanbul": "^2.0.0",
36+
"eslint": "^2.9.0",
37+
"eslint-plugin-mocha": "^2.2.0",
38+
"eslint-plugin-require-path-exists": "^1.1.5",
39+
"istanbul": "^0.4.3",
40+
"karma": "^1.1.0",
41+
"karma-browserify": "^5.0.4",
42+
"karma-chrome-launcher": "^1.0.1",
43+
"karma-coverage": "^1.0.0",
44+
"karma-junit-reporter": "^1.0.0",
45+
"karma-mocha": "^1.0.1",
46+
"karma-phantomjs-launcher": "^1.0.0",
47+
"karma-sauce-launcher": "^1.0.0",
48+
"karma-spec-reporter": "0.0.26",
49+
"mocha": "^2.2.5",
50+
"npm-check": "^5.2.1",
51+
"phantomjs-prebuilt": "^2.1.7",
52+
"watchify": "^3.7.0"
53+
}
54+
}
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: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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 Wishpond = require('../lib');
8+
9+
describe('Wishpond', function() {
10+
var analytics;
11+
var wishpond;
12+
var options = {
13+
siteId: '696791',
14+
apiKey: '591bb1914bdf'
15+
};
16+
17+
beforeEach(function() {
18+
analytics = new Analytics();
19+
wishpond = new Wishpond(options);
20+
analytics.use(Wishpond);
21+
analytics.use(tester);
22+
analytics.add(wishpond);
23+
});
24+
25+
afterEach(function() {
26+
analytics.restore();
27+
analytics.reset();
28+
// FIXME(ndhoule): window.addEventListener('message', ...) handlers aren't
29+
// properly being cleaned up in tests and are causing uncaught exceptions.
30+
// We should capture these events and remove them to prevent uncaught
31+
// exceptions in the test suite
32+
// wishpond.reset();
33+
// sandbox();
34+
});
35+
36+
it('should have the right settings', function() {
37+
analytics.compare(Wishpond, integration('Wishpond')
38+
.global('Wishpond')
39+
.option('siteId', '')
40+
.option('apiKey', ''));
41+
});
42+
43+
describe('before loading', function() {
44+
beforeEach(function() {
45+
analytics.stub(wishpond, 'load');
46+
});
47+
48+
describe('#initialize', function() {
49+
it('should create the window.Wishpond object', function() {
50+
analytics.assert(!window.Wishpond);
51+
analytics.initialize();
52+
analytics.assert(window.Wishpond);
53+
});
54+
55+
it('should call #load', function() {
56+
analytics.initialize();
57+
analytics.called(wishpond.load);
58+
});
59+
});
60+
});
61+
62+
describe('loading', function() {
63+
it('should load', function(done) {
64+
analytics.load(wishpond, done);
65+
});
66+
});
67+
68+
describe('after loading', function() {
69+
beforeEach(function(done) {
70+
analytics.once('ready', done);
71+
analytics.initialize();
72+
});
73+
74+
describe('#identify', function() {
75+
beforeEach(function() {
76+
analytics.stub(window.Wishpond.Tracker, 'identify');
77+
});
78+
79+
it('should send an id', function() {
80+
analytics.identify('id');
81+
analytics.called(window.Wishpond.Tracker.identify, 'id', { id: 'id' });
82+
});
83+
84+
it('should not send only traits', function() {
85+
analytics.identify({ trait: true });
86+
analytics.didNotCall(window.Wishpond.Tracker.identify);
87+
});
88+
89+
it('should send an id and traits', function() {
90+
analytics.identify('id', { trait: true, email: 'blackwidow@shield.gov' });
91+
analytics.called(window.Wishpond.Tracker.identify, 'id', { id: 'id', trait: true, email: 'blackwidow@shield.gov' });
92+
});
93+
94+
it('should alias createdAt to created_at', function() {
95+
var date = new Date();
96+
analytics.identify('id', { createdAt: date });
97+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
98+
id: 'id',
99+
created_at: date
100+
});
101+
});
102+
103+
it('should alias updatedAt to updated_at', function() {
104+
var date = new Date();
105+
analytics.identify('id', { updatedAt: date });
106+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
107+
id: 'id',
108+
updated_at: date
109+
});
110+
});
111+
112+
it('should alias firstName to first_name', function() {
113+
var name = 'Anderson';
114+
analytics.identify('id', { firstName: name });
115+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
116+
id: 'id',
117+
first_name: name
118+
});
119+
});
120+
121+
it('should alias lastName to last_name', function() {
122+
var name = 'Saunders';
123+
analytics.identify('id', { lastName: name });
124+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
125+
id: 'id',
126+
last_name: name
127+
});
128+
});
129+
130+
it('should alias phoneNumber to phone_number', function() {
131+
var phone = '778 681 7804';
132+
analytics.identify('id', { phoneNumber: phone });
133+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
134+
id: 'id',
135+
phone_number: phone
136+
});
137+
});
138+
139+
it('should alias leadScore to lead_score', function() {
140+
var score = 5;
141+
analytics.identify('id', { leadScore: score });
142+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
143+
id: 'id',
144+
lead_score: score
145+
});
146+
});
147+
148+
it('should not alias notDefault to not_default', function() {
149+
var value = 'yes';
150+
analytics.identify('id', { notDefault: value });
151+
analytics.called(window.Wishpond.Tracker.identify, 'id', {
152+
id: 'id',
153+
notDefault: value
154+
});
155+
});
156+
});
157+
158+
describe('#track', function() {
159+
beforeEach(function() {
160+
analytics.stub(window.Wishpond.Tracker, 'track');
161+
});
162+
163+
it('should send an event', function() {
164+
analytics.track('event');
165+
analytics.called(window.Wishpond.Tracker.track, 'event');
166+
});
167+
168+
it('should send an event and properties', function() {
169+
analytics.track('event', { property: true });
170+
analytics.called(window.Wishpond.Tracker.track, 'event', { property: true });
171+
});
172+
});
173+
});
174+
});

0 commit comments

Comments
 (0)