Skip to content

Commit cfc80e1

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

File tree

6 files changed

+766
-0
lines changed

6 files changed

+766
-0
lines changed

integrations/olark/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-09-09
14+
==================
15+
16+
* Adding support for inline chat
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/olark/README.md

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

integrations/olark/lib/index.js

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var https = require('use-https');
8+
var integration = require('@segment/analytics.js-integration');
9+
var tick = require('next-tick');
10+
11+
/**
12+
* Expose `Olark` integration.
13+
*/
14+
15+
var Olark = module.exports = integration('Olark')
16+
.assumesPageview()
17+
.global('olark')
18+
.option('groupId', '')
19+
.option('identify', true)
20+
.option('listen', false)
21+
.option('page', true)
22+
.option('siteId', '')
23+
.option('track', false)
24+
.option('inline', false);
25+
26+
/**
27+
* The context for this integration.
28+
*/
29+
30+
var integrationContext = {
31+
name: 'olark',
32+
version: '1.0.0'
33+
};
34+
35+
/**
36+
* Initialize.
37+
*
38+
* http://www.olark.com/documentation
39+
* https://www.olark.com/documentation/javascript/api.chat.setOperatorGroup
40+
*
41+
* @api public
42+
*/
43+
44+
Olark.prototype.initialize = function() {
45+
var self = this;
46+
this.load(function() {
47+
tick(self.ready);
48+
});
49+
50+
// assign chat to a specific site
51+
var groupId = this.options.groupId;
52+
if (groupId) api('chat.setOperatorGroup', { group: groupId });
53+
54+
// keep track of the widget's open state
55+
api('box.onExpand', function() { self._open = true; });
56+
api('box.onShrink', function() { self._open = false; });
57+
58+
// record events
59+
if (this.options.listen) this.attachListeners();
60+
};
61+
62+
/**
63+
* Load.
64+
*
65+
* @api private
66+
* @param {Function} callback
67+
*/
68+
69+
Olark.prototype.load = function(callback) {
70+
/* eslint-disable */
71+
window.olark||(function(c){var f=window,d=document,l=https()?"https:":"http:",z=c.name,r="load";var nt=function(){f[z]=function(){(a.s=a.s||[]).push(arguments)};var a=f[z]._={},q=c.methods.length;while (q--) {(function(n){f[z][n]=function(){f[z]("call",n,arguments)}})(c.methods[q])}a.l=c.loader;a.i=nt;a.p={ 0:+new Date() };a.P=function(u){a.p[u]=new Date()-a.p[0]};function s(){a.P(r);f[z](r)}f.addEventListener?f.addEventListener(r,s,false):f.attachEvent("on"+r,s);var ld=function(){function p(hd){hd="head";return ["<",hd,"></",hd,"><",i,' onl' + 'oad="var d=',g,";d.getElementsByTagName('head')[0].",j,"(d.",h,"('script')).",k,"='",l,"//",a.l,"'",'"',"></",i,">"].join("")}var i="body",m=d[i];if (!m) {return setTimeout(ld,100)}a.P(1);var j="appendChild",h="createElement",k="src",n=d[h]("div"),v=n[j](d[h](z)),b=d[h]("iframe"),g="document",e="domain",o;n.style.display="none";m.insertBefore(n,m.firstChild).id=z;b.frameBorder="0";b.id=z+"-loader";if (/MSIE[ ]+6/.test(navigator.userAgent)) {b.src="javascript:false"}b.allowTransparency="true";v[j](b);try {b.contentWindow[g].open()}catch (w) {c[e]=d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try {var t=b.contentWindow[g];t.write(p());t.close()}catch (x) {b[k]=o+'d.write("'+p().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}a.P(2)};ld()};nt()})({ loader: "static.olark.com/jsclient/loader0.js", name:"olark", methods:["configure","extend","declare","identify"] });
72+
/* eslint-enable */
73+
74+
// check if chat should be loaded as `inline chat`
75+
if (this.options.inline) configure('box.inline', true);
76+
77+
window.olark.identify(this.options.siteId);
78+
callback();
79+
};
80+
81+
/**
82+
* Loaded?
83+
*
84+
* @api private
85+
* @return {boolean}
86+
*/
87+
88+
Olark.prototype.loaded = function() {
89+
return !!window.olark;
90+
};
91+
92+
/**
93+
* Page.
94+
*
95+
* @param {Facade} page
96+
*/
97+
98+
Olark.prototype.page = function(page) {
99+
if (!this.options.page) return;
100+
var props = page.properties();
101+
var name = page.fullName();
102+
if (!name && !props.url) return;
103+
104+
name = name ? name + ' page' : props.url;
105+
this.notify('looking at ' + name);
106+
};
107+
108+
/**
109+
* Identify.
110+
*
111+
* @param {Facade} identify
112+
*/
113+
114+
Olark.prototype.identify = function(identify) {
115+
if (!this.options.identify) return;
116+
117+
var username = identify.username();
118+
var traits = identify.traits();
119+
var id = identify.userId();
120+
var email = identify.email();
121+
var phone = identify.phone();
122+
var name = identify.name() || identify.firstName();
123+
124+
if (traits) api('visitor.updateCustomFields', traits);
125+
if (email) api('visitor.updateEmailAddress', { emailAddress: email });
126+
if (phone) api('visitor.updatePhoneNumber', { phoneNumber: phone });
127+
if (name) api('visitor.updateFullName', { fullName: name });
128+
129+
// figure out best nickname
130+
var nickname = name || email || username || id;
131+
if (name && email) nickname += ' (' + email + ')';
132+
if (nickname) api('chat.updateVisitorNickname', { snippet: nickname });
133+
};
134+
135+
/**
136+
* Track.
137+
*
138+
* @api public
139+
* @param {Facade} track
140+
*/
141+
142+
Olark.prototype.track = function(track) {
143+
if (!this.options.track) return;
144+
this.notify('visitor triggered "' + track.event() + '"');
145+
};
146+
147+
/**
148+
* Listen for events.
149+
*/
150+
151+
Olark.prototype.attachListeners = function() {
152+
var self = this;
153+
154+
api('chat.onBeginConversation', function() {
155+
self.analytics.track(
156+
'Live Chat Conversation Started',
157+
{},
158+
{
159+
context: { integration: integrationContext },
160+
integrations: { Olark: false }
161+
}
162+
);
163+
});
164+
165+
// Callback accepts `event`
166+
// TODO: We might eventually send information about the event through Segment
167+
api('chat.onMessageToOperator', function() {
168+
self.analytics.track(
169+
'Live Chat Message Sent',
170+
{},
171+
{
172+
context: { integration: integrationContext },
173+
integrations: { Olark: false }
174+
}
175+
);
176+
});
177+
178+
// Callback accepts `event`
179+
// TODO: We might eventually send information about the event through Segment
180+
api('chat.onMessageToVisitor', function() {
181+
self.analytics.track(
182+
'Live Chat Message Received',
183+
{},
184+
{
185+
context: { integration: integrationContext },
186+
integrations: { Olark: false }
187+
}
188+
);
189+
});
190+
};
191+
192+
/**
193+
* Send a notification `message` to the operator, only when a chat is active and
194+
* when the chat is open.
195+
*
196+
* @api private
197+
* @param {string} message
198+
*/
199+
200+
Olark.prototype.notify = function(message) {
201+
if (!this._open) return;
202+
203+
// lowercase since olark does
204+
message = message.toLowerCase();
205+
206+
api('visitor.getDetails', function(data) {
207+
if (!data || !data.isConversing) return;
208+
api('chat.sendNotificationToOperator', { body: message });
209+
});
210+
};
211+
212+
/**
213+
* Helper for Olark API calls.
214+
*
215+
* @api private
216+
* @param {string} action
217+
* @param {Object} value
218+
*/
219+
220+
function api(action, value) {
221+
window.olark('api.' + action, value);
222+
}
223+
224+
function configure(action, value) {
225+
window.olark.configure(action, value);
226+
}

integrations/olark/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-olark",
3+
"description": "The Olark analytics.js integration.",
4+
"version": "2.0.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"olark"
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/olark#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+
"next-tick": "^0.2.2",
28+
"use-https": "^0.1.1"
29+
},
30+
"devDependencies": {
31+
"@segment/analytics.js-core": "^3.0.0",
32+
"@segment/analytics.js-integration-tester": "^2.0.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.1.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+
"once-component": "^0.0.1",
53+
"phantomjs-prebuilt": "^2.1.7",
54+
"watchify": "^3.7.0"
55+
}
56+
}

integrations/olark/test/.eslintrc

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)