Skip to content

Commit 7ca3cd7

Browse files
gaurishankerGaurishanker GaurGaurav Nandadanieljackins
authored
Fix UUID (#557)
* Send uuid along with experiment id and variation name and call identify * call identify only once per load * updated version and HISTORY.md * stub for identify * Fix failing tests * added test cases for identify method * added vwoUserId as a trait in identify call * added vwoUserId as a trait in identify call Testing completed successfully on local machine, added test cases for identify method calls Co-authored-by: Gaurishanker Gaur <gaurishanker.gaur@wingify.com> Co-authored-by: Gaurav Nanda <gaurav.nanda@wingify.com> Co-authored-by: dsjackins <daniel.jackins@segment.com>
1 parent 0964b11 commit 7ca3cd7

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

integrations/visual-website-optimizer/HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.4.2 / 2021-02-09
2+
==================
3+
4+
* Send VWO UUID in every track call.
5+
* Send identify call once every page load.
6+
17
2.4.1 / 2019-12-04
28
==================
39

integrations/visual-website-optimizer/lib/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var VWO = (module.exports = integration('Visual Website Optimizer')
1919
.global('_vis_opt_revenue_conversion')
2020
.global('_vwo_exp')
2121
.global('_vwo_exp_ids')
22+
.global('VWO')
2223
.option('accountId')
2324
.option('useAsyncSmartCode', false)
2425
.option('settingsTolerance', 2000)
@@ -114,16 +115,22 @@ VWO.prototype.replay = function() {
114115
VWO.prototype.roots = function() {
115116
var analytics = this.analytics;
116117
var self = this;
117-
118+
var identifyCalled = false;
118119
rootExperiments(function(err, data) {
119120
each(data, function(experimentId, variationName) {
121+
const uuid = window.VWO.data.vin.uuid;
120122
var props = {
121123
experimentId: experimentId,
122-
variationName: variationName
124+
variationName: variationName,
125+
vwoUserId: uuid
123126
};
124127

125128
if (self.options.experimentNonInteraction) props.nonInteraction = 1;
126-
129+
130+
if(identifyCalled === false) {
131+
analytics.identify({vwoUserId: uuid});
132+
identifyCalled = true;
133+
}
127134
analytics.track('Experiment Viewed', props, {
128135
context: { integration: integrationContext }
129136
});

integrations/visual-website-optimizer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-visual-website-optimizer",
33
"description": "The Visual Website Optimizer analytics.js integration.",
4-
"version": "2.4.1",
4+
"version": "2.4.2",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/visual-website-optimizer/test/index.test.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ describe('Visual Website Optimizer', function() {
3030
}
3131
};
3232
window._vis_opt_queue = [];
33+
window.VWO = {
34+
data: {
35+
vin: {
36+
uuid: 1
37+
}
38+
}
39+
};
3340
});
3441

3542
afterEach(function() {
@@ -125,6 +132,7 @@ describe('Visual Website Optimizer', function() {
125132
describe('#roots', function() {
126133
beforeEach(function() {
127134
analytics.stub(analytics, 'track');
135+
analytics.stub(analytics, 'identify');
128136
});
129137

130138
it('should send active experiments if experiment is ready', function(done) {
@@ -134,13 +142,13 @@ describe('Visual Website Optimizer', function() {
134142

135143
tick(function() {
136144
window._vis_opt_queue[1]();
137-
138145
analytics.called(
139146
analytics.track,
140147
'Experiment Viewed',
141148
{
142149
experimentId: '1',
143-
variationName: 'Variation'
150+
variationName: 'Variation',
151+
vwoUserId: 1
144152
},
145153
{
146154
context: {
@@ -185,6 +193,44 @@ describe('Visual Website Optimizer', function() {
185193
});
186194
});
187195

196+
it('should send identify call if experiment is ready', function(done) {
197+
vwo.options.listen = true;
198+
analytics.initialize();
199+
analytics.page();
200+
201+
tick(function() {
202+
window._vis_opt_queue[1]();
203+
analytics.called(
204+
analytics.identify,
205+
{
206+
vwoUserId: 1
207+
}
208+
);
209+
210+
done();
211+
});
212+
});
213+
214+
it('should not send identify call if experiment is not ready', function(done) {
215+
vwo.options.listen = true;
216+
window._vwo_exp[1].ready = false;
217+
analytics.initialize();
218+
analytics.page();
219+
220+
tick(function() {
221+
window._vis_opt_queue[1]();
222+
analytics.didNotCall(
223+
analytics.identify,
224+
{
225+
vwoUserId: 1
226+
}
227+
);
228+
229+
done();
230+
});
231+
});
232+
233+
188234
it('should send experiment views as non-interactive if enabled', function(done) {
189235
vwo.options.listen = true;
190236
vwo.options.experimentNonInteraction = true;
@@ -200,6 +246,7 @@ describe('Visual Website Optimizer', function() {
200246
{
201247
experimentId: '1',
202248
variationName: 'Variation',
249+
vwoUserId: 1,
203250
nonInteraction: 1
204251
},
205252
{
@@ -259,7 +306,8 @@ describe('Visual Website Optimizer', function() {
259306
'Experiment Viewed',
260307
{
261308
experimentId: '1',
262-
variationName: 'Variation'
309+
variationName: 'Variation',
310+
vwoUserId: 1
263311
},
264312
{
265313
context: {

0 commit comments

Comments
 (0)