Skip to content

Commit e30c94a

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

File tree

6 files changed

+353
-0
lines changed

6 files changed

+353
-0
lines changed

integrations/userlike/HISTORY.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.3 / 2016-05-07
9+
==================
10+
11+
* Bump Analytics.js core, tester, integration to use Facade 2.x
12+
13+
1.0.2 / 2015-06-30
14+
==================
15+
16+
* Replace analytics.js dependency with analytics.js-core
17+
18+
1.0.1 / 2015-06-24
19+
==================
20+
21+
* Bump analytics.js-integration version
22+
23+
1.0.0 / 2015-06-09
24+
==================
25+
26+
* Initial commit :sparkles:

integrations/userlike/README.md

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

integrations/userlike/lib/index.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var Identify = require('segmentio-facade').Identify;
8+
var clone = require('component-clone');
9+
var integration = require('@segment/analytics.js-integration');
10+
11+
/**
12+
* Expose Userlike integration.
13+
*/
14+
15+
var Userlike = module.exports = integration('Userlike')
16+
.assumesPageview()
17+
.global('userlikeConfig')
18+
.global('userlikeData')
19+
.option('secretKey', '')
20+
.option('listen', false)
21+
.tag('<script src="//userlike-cdn-widgets.s3-eu-west-1.amazonaws.com/{{ secretKey }}.js">');
22+
23+
/**
24+
* The context for this integration.
25+
*/
26+
27+
var integrationContext = {
28+
name: 'userlike',
29+
version: '1.0.0'
30+
};
31+
32+
/**
33+
* Initialize.
34+
*
35+
* @api public
36+
*/
37+
38+
Userlike.prototype.initialize = function() {
39+
var self = this;
40+
var segment_base_info = clone(this.options);
41+
var user = this.analytics.user();
42+
var identify = new Identify({
43+
userId: user.id(),
44+
traits: user.traits()
45+
});
46+
47+
// FIXME: Should this be a global? Waiting for answer from Userlike folks as
48+
// of 5/19/2015
49+
//
50+
// https://github.com/thomassittig/analytics.js-integrations/commit/e8fb4c067abe7f8549d0e0153504fd24a9aa4b53
51+
// segment_base_info = clone(this.options);
52+
53+
segment_base_info.visitor = {
54+
name: identify.name(),
55+
email: identify.email()
56+
};
57+
58+
if (!window.userlikeData) window.userlikeData = { custom: {} };
59+
window.userlikeData.custom.segmentio = segment_base_info;
60+
61+
this.load(function() {
62+
if (self.options.listen) self.attachListeners();
63+
self.ready();
64+
});
65+
};
66+
67+
/**
68+
* Loaded?
69+
*
70+
* @return {Boolean}
71+
*/
72+
73+
Userlike.prototype.loaded = function() {
74+
return !!(window.userlikeConfig && window.userlikeData);
75+
};
76+
77+
/**
78+
* Listen for chat events.
79+
*
80+
* TODO: As of 4/17/2015, Userlike doesn't give access to the message body in events.
81+
* Revisit this/send it when they do.
82+
*/
83+
84+
Userlike.prototype.attachListeners = function() {
85+
var self = this;
86+
window.userlikeTrackingEvent = function(eventName, globalCtx, sessionCtx) {
87+
if (eventName === 'chat_started') {
88+
self.analytics.track(
89+
'Live Chat Conversation Started',
90+
{ agentId: sessionCtx.operator_id, agentName: sessionCtx.operator_name },
91+
{ context: { integration: integrationContext }
92+
});
93+
}
94+
if (eventName === 'message_operator_terminating') {
95+
self.analytics.track(
96+
'Live Chat Message Sent',
97+
{ agentId: sessionCtx.operator_id, agentName: sessionCtx.operator_name },
98+
{ context: { integration: integrationContext }
99+
});
100+
}
101+
if (eventName === 'message_client_terminating') {
102+
self.analytics.track(
103+
'Live Chat Message Received',
104+
{ agentId: sessionCtx.operator_id, agentName: sessionCtx.operator_name },
105+
{ context: { integration: integrationContext }
106+
});
107+
}
108+
if (eventName === 'chat_quit') {
109+
self.analytics.track(
110+
'Live Chat Conversation Ended',
111+
{ agentId: sessionCtx.operator_id, agentName: sessionCtx.operator_name },
112+
{ context: { integration: integrationContext }
113+
});
114+
}
115+
};
116+
};

integrations/userlike/package.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "@segment/analytics.js-integration-userlike",
3+
"description": "The Userlike analytics.js integration.",
4+
"version": "2.0.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"userlike"
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/userlike#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+
"component-clone": "^0.2.2",
28+
"segmentio-facade": "^3.0.3"
29+
},
30+
"devDependencies": {
31+
"@segment/analytics.js-core": "^3.0.0",
32+
"@segment/analytics.js-integration-tester": "^3.1.0",
33+
"@segment/clear-env": "^2.0.0",
34+
"@segment/eslint-config": "^3.1.1",
35+
"browserify": "^13.0.0",
36+
"browserify-istanbul": "^2.0.0",
37+
"eslint": "^2.9.0",
38+
"eslint-plugin-mocha": "^2.2.0",
39+
"eslint-plugin-require-path-exists": "^1.1.5",
40+
"istanbul": "^0.4.3",
41+
"karma": "1.3.0",
42+
"karma-browserify": "^5.0.4",
43+
"karma-chrome-launcher": "^1.0.1",
44+
"karma-coverage": "^1.0.0",
45+
"karma-junit-reporter": "^1.0.0",
46+
"karma-mocha": "1.0.1",
47+
"karma-phantomjs-launcher": "^1.0.0",
48+
"karma-sauce-launcher": "^1.0.0",
49+
"karma-spec-reporter": "0.0.26",
50+
"mocha": "^2.2.5",
51+
"npm-check": "^5.2.1",
52+
"phantomjs-prebuilt": "^2.1.7",
53+
"watchify": "^3.7.0"
54+
}
55+
}
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: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 Userlike = require('../lib/');
8+
9+
describe('Userlike', function() {
10+
var userlike;
11+
var analytics;
12+
var options = {
13+
secretKey: 'c3e839df9320d85ff590d07477c32cff837c02d7d4acaa18af91205800606b6c',
14+
listen: true
15+
};
16+
17+
beforeEach(function() {
18+
analytics = new Analytics();
19+
userlike = new Userlike(options);
20+
analytics.use(Userlike);
21+
analytics.use(tester);
22+
analytics.add(userlike);
23+
});
24+
25+
afterEach(function() {
26+
analytics.restore();
27+
analytics.reset();
28+
userlike.reset();
29+
sandbox();
30+
});
31+
32+
it('should have the right settings', function() {
33+
analytics.compare(Userlike, integration('Userlike')
34+
.assumesPageview()
35+
.global('userlikeConfig')
36+
.global('userlikeData')
37+
.option('secretKey', ''));
38+
});
39+
40+
describe('before loading', function() {
41+
beforeEach(function() {
42+
analytics.identify({ email: 'email', name: 'name' });
43+
analytics.stub(userlike, 'load');
44+
});
45+
46+
describe('#initialize', function() {
47+
it('should create window.userlikeData', function() {
48+
analytics.initialize();
49+
analytics.page();
50+
analytics.deepEqual(window.userlikeData, {
51+
custom: {
52+
segmentio: {
53+
secretKey: options.secretKey,
54+
listen: true,
55+
visitor: {
56+
name: 'name',
57+
email: 'email'
58+
}
59+
}
60+
}
61+
});
62+
});
63+
64+
it('should call #load', function() {
65+
analytics.initialize();
66+
analytics.page();
67+
analytics.called(userlike.load);
68+
});
69+
});
70+
});
71+
72+
describe('loading', function() {
73+
it('should load', function(done) {
74+
analytics.load(userlike, done);
75+
});
76+
});
77+
78+
describe('after loading', function() {
79+
beforeEach(function(done) {
80+
analytics.once('ready', done);
81+
analytics.initialize();
82+
analytics.page();
83+
});
84+
85+
// TODO: The way Userlike's API is structured makes starting it
86+
// programmatically pretty hard. Revisit these tests
87+
xdescribe('#listen', function() {
88+
beforeEach(function() {
89+
/*
90+
analytics.once('ready', done);
91+
analytics.initialize();
92+
analytics.stub(analytics, 'track');
93+
*/
94+
});
95+
96+
it('should send a chat started event', function() {
97+
/*
98+
setTimeout(function() {
99+
userlikeStartChat();
100+
}, 1000);
101+
setTimeout(function() {
102+
analytics.called(analytics.track, 'Live Chat Conversation Started', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}});
103+
}, 2000);
104+
*/
105+
});
106+
107+
it('should send a chat sent event', function() {
108+
/*
109+
setTimeout(function() {
110+
userlikeSendEvent();
111+
}, 1000);
112+
setTimeout(function() {
113+
analytics.called(analytics.track, 'Live Chat Message Sent', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}});
114+
}, 2000);
115+
*/
116+
});
117+
118+
it('should send a chat received event', function() {
119+
/*
120+
setTimeout(function() {
121+
userlikeSendEvent();
122+
}, 1000);
123+
setTimeout(function() {
124+
analytics.called(analytics.track, 'Live Chat Message Received', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}});
125+
}, 2000);
126+
*/
127+
});
128+
129+
it('should send a chat ended event', function() {
130+
/*
131+
setTimeout(function() {
132+
userlikeQuitChat();
133+
}, 1000);
134+
setTimeout(function() {
135+
analytics.called(analytics.track, 'Live Chat Conversation Ended', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}});
136+
}, 2000);
137+
*/
138+
});
139+
});
140+
});
141+
});

0 commit comments

Comments
 (0)