Skip to content

Commit df920c3

Browse files
author
Julio Farah
authored
add survicate and walkme (#48)
* add survicate * add walkme * Ignore tests for survicate and walkme
1 parent dfde209 commit df920c3

File tree

19 files changed

+875
-2
lines changed

19 files changed

+875
-2
lines changed

integrations/survicate/.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/browser/legacy"
3+
}

integrations/survicate/HISTORY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
1.0.0 / 2019-03-30
2+
==================
3+
4+
* Initial commit :sparkles:
5+
6+
1.0.1 / 2019-04-01
7+
==================
8+
9+
* Flatten Objects
10+
11+
1.0.2 / 2019-05-06
12+
==================
13+
14+
* Always use HTTPS
15+
* Loader smallfix

integrations/survicate/LICENSE

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 <[email protected]>
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/survicate/README.md

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

integrations/survicate/lib/index.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var integration = require('@segment/analytics.js-integration');
8+
var when = require('do-when');
9+
var del = require('obj-case').del;
10+
var is = require('is');
11+
var snake = require('change-case').snake;
12+
var each = require('@ndhoule/each');
13+
14+
15+
/**
16+
* Expose `Survicate` integration.
17+
*/
18+
19+
var Survicate = module.exports = integration('Survicate')
20+
.global('_sva')
21+
.option('workspaceKey', '')
22+
.tag('<script src="https://survey.survicate.com/workspaces/{{ workspaceKey }}/web_surveys.js">');
23+
24+
/**
25+
* Initialize.
26+
*
27+
* @api public
28+
*/
29+
30+
Survicate.prototype.initialize = function() {
31+
var self = this;
32+
this.load(function() {
33+
when(function() { return self.loaded(); }, self.ready);
34+
});
35+
};
36+
37+
/**
38+
* Loaded?
39+
*
40+
* @api private
41+
* @return {boolean}
42+
*/
43+
44+
Survicate.prototype.loaded = function() {
45+
return !!(window._svc && window._svc.initialized);
46+
};
47+
48+
/**
49+
* Identify.
50+
*
51+
* @api public
52+
* @param {Identify} identify
53+
*/
54+
55+
Survicate.prototype.identify = function(identify) {
56+
var traits = identify.traits({ userId: 'user_id' });
57+
del(traits, 'id');
58+
59+
each(function(value, key) {
60+
if (is.object(value)) {
61+
// flatten object
62+
del(traits, key);
63+
each(function(innerValue, innerKey) {
64+
traits[snake(key) + '_' + snake(innerKey)] = innerValue;
65+
}, value);
66+
} else if (is.array(value)) {
67+
// drop arrays
68+
del(traits, key);
69+
} else {
70+
// convert camelCase to snake_case
71+
del(traits, key);
72+
traits[snake(key)] = value;
73+
}
74+
}, traits);
75+
76+
window._sva.setVisitorTraits(traits);
77+
};
78+
79+
/**
80+
* Group.
81+
*
82+
* @api public
83+
* @param {Group} group
84+
*/
85+
86+
Survicate.prototype.group = function(group) {
87+
var traits = group.traits({
88+
groupId: 'group_id'
89+
});
90+
del(traits, 'id');
91+
92+
each(function(value, key) {
93+
if (is.object(value)) {
94+
// flatten object
95+
del(traits, key);
96+
each(function(innerValue, innerKey) {
97+
traits['group_' + snake(key) + '_' + snake(innerKey)] = innerValue;
98+
}, value);
99+
} else if (is.array(value)) {
100+
// drop arrays
101+
del(traits, key);
102+
} else if (key !== 'group_id') {
103+
// convert camelCase to snake_case
104+
del(traits, key);
105+
traits['group_' + snake(key)] = value;
106+
}
107+
}, traits);
108+
109+
window._sva.setVisitorTraits(traits);
110+
};

integrations/survicate/package.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@survicate/analytics.js-integration-survicate",
3+
"description": "The Survicate analytics.js integration.",
4+
"version": "1.0.2",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"survicate"
10+
],
11+
"main": "lib/index.js",
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/Survicate/analytics.js-integration-survicate.git"
15+
},
16+
"author": "Survicate <[email protected]>",
17+
"license": "SEE LICENSE IN LICENSE",
18+
"bugs": {
19+
"url": "https://github.com/Survicate/analytics.js-integration-survicate/issues"
20+
},
21+
"homepage": "https://github.com/Survicate/analytics.js-integration-survicate#readme",
22+
"dependencies": {
23+
"@segment/analytics.js-integration": "^2.1.0",
24+
"do-when": "^1.0.0",
25+
"change-case": "^3.1.0",
26+
"@ndhoule/each": "^2.0.1",
27+
"is": "^3.3.0"
28+
},
29+
"devDependencies": {
30+
"@segment/analytics.js-core": "^3.8.2",
31+
"@segment/analytics.js-integration-tester": "^3.1.1",
32+
"@segment/clear-env": "^2.1.1",
33+
"@segment/eslint-config": "^3.1.1",
34+
"browserify": "^16.2.3",
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": "^4.1.0",
41+
"karma-browserify": "^6.0.0",
42+
"karma-chrome-launcher": "^2.2.0",
43+
"karma-coverage": "^1.0.0",
44+
"karma-junit-reporter": "^1.0.0",
45+
"karma-mocha": "^1.3.0",
46+
"karma-phantomjs-launcher": "^1.0.0",
47+
"karma-sauce-launcher": "^2.0.2",
48+
"karma-spec-reporter": "0.0.26",
49+
"mocha": "^6.1.4",
50+
"npm-check": "^5.2.1",
51+
"phantomjs-prebuilt": "^2.1.7",
52+
"watchify": "^3.7.0"
53+
}
54+
}

integrations/survicate/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)