Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.

Commit 22c0158

Browse files
committed
improvement: merge viewport and targeting
1 parent 54c57bc commit 22c0158

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/__tests__/environment.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ describe('Environment', function () {
1010
path: expect.any(String),
1111
query: expect.any(Object),
1212
}),
13-
viewport: expect.objectContaining({
13+
targeting: expect.objectContaining({
1414
doNotTrack: expect.any(Boolean),
1515
width: expect.any(Number),
1616
height: expect.any(Number),
1717
userAgent: expect.any(String),
1818
}),
19-
targeting: expect.any(Object),
2019
}))
2120
});
2221

@@ -34,13 +33,12 @@ describe('Environment', function () {
3433
path: expect.any(String),
3534
query: expect.any(Object),
3635
}),
37-
viewport: expect.objectContaining({
36+
targeting: expect.objectContaining({
3837
doNotTrack: expect.any(Boolean),
3938
width: expect.any(Number),
4039
height: expect.any(Number),
4140
userAgent: expect.any(String),
4241
}),
43-
targeting: expect.any(Object),
4442
}));
4543
expect(variate.env.view.path).toBeDefined();
4644
expect(variate.env.view.path).toEqual('/');
@@ -60,13 +58,12 @@ describe('Environment', function () {
6058
path: expect.any(String),
6159
query: expect.any(Object),
6260
}),
63-
viewport: expect.objectContaining({
61+
targeting: expect.objectContaining({
6462
doNotTrack: expect.any(Boolean),
6563
width: expect.any(Number),
6664
height: expect.any(Number),
6765
userAgent: expect.any(String),
6866
}),
69-
targeting: expect.any(Object),
7067
}))
7168
});
7269

src/__tests__/non-browser.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ it('Environment can degrade gracefully if window is undefined', () => {
1717
url: expect.any(String),
1818
query: expect.any(Object),
1919
}),
20-
viewport: expect.objectContaining({
20+
targeting: expect.objectContaining({
2121
doNotTrack: expect.any(Boolean),
2222
width: expect.any(Number),
2323
height: expect.any(Number),
2424
userAgent: expect.any(Boolean),
2525
}),
26-
targeting: expect.any(Object),
2726
}))
2827
});

src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Variate {
9595
};
9696

9797
// Viewport information
98-
const viewport = {
98+
const targeting = {
9999
visitorId: this.getUUID(),
100100
doNotTrack: env.doNotTrack(),
101101
width: env.width(),
@@ -104,9 +104,15 @@ class Variate {
104104
};
105105

106106
// Targeting information
107-
const targeting = get(value, 'targeting', {default: {}});
107+
const customTargeting = get(value, 'targeting', {default: {}});
108108

109-
this._env = Object.assign({}, this._env, {view, viewport, targeting});
109+
this._env = Object.assign({}, this._env, {
110+
view,
111+
targeting: {
112+
...targeting,
113+
...customTargeting
114+
}
115+
});
110116

111117
if (this._options.debug) {
112118
console.groupCollapsed(debug.SETUP_ENVIRONMENT);
@@ -225,8 +231,6 @@ class Variate {
225231
this.isReady = true;
226232
this._options.debug && console.timeEnd('[BENCHMARK] Variate Initialization');
227233

228-
console.log('NAH', this._options.tracking.enabled, this._options.pageview);
229-
230234
if (this._options.tracking.enabled && this._options.pageview) {
231235
this.track('Pageview', EventTypes.PAGEVIEW);
232236
}

0 commit comments

Comments
 (0)