Skip to content

Commit 0c063c3

Browse files
authored
Don't allow AB test to reset once it's set (#3945)
1 parent f303c22 commit 0c063c3

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

packages/homepage/src/pages/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { identify } from '@codesandbox/common/lib/utils/analytics';
32

43
import TitleAndMetaTags from '../components/TitleAndMetaTags';
54
import Layout, { WRAPPER_STYLING } from '../components/layout';
@@ -14,6 +13,8 @@ import Share from '../screens/home/share';
1413
import Join from '../screens/home/join';
1514
import Explore from '../screens/home/explore';
1615

16+
import { identifyFromCookie } from '../utils/identifyFromCookie';
17+
1718
// eslint-disable-next-line
1819
console.log(
1920
'Hi, We love curious people that dive in to see how things are working! We are always looking for talented, hard working people. Drop us a line and show us your work. We are hiring: https://codesandbox.io/jobs'
@@ -59,6 +60,6 @@ const Homepage = () => (
5960
</Layout>
6061
);
6162

62-
identify('hero0420', 'A');
63+
identifyFromCookie('heroAB', 'hero0420');
6364

6465
export default Homepage;

packages/homepage/src/pages/index2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { identify } from '@codesandbox/common/lib/utils/analytics';
32

43
import TitleAndMetaTags from '../components/TitleAndMetaTags';
54
import Layout, { WRAPPER_STYLING } from '../components/layout';
@@ -13,6 +12,8 @@ import Share from '../screens/home/share';
1312
import Join from '../screens/home/join';
1413
import Explore from '../screens/home/explore';
1514

15+
import { identifyFromCookie } from '../utils/identifyFromCookie';
16+
1617
// eslint-disable-next-line
1718
console.log(
1819
'Hi, We love curious people that dive in to see how things are working! We are always looking for talented, hard working people. Drop us a line and show us your work. We are hiring: https://codesandbox.io/jobs'
@@ -57,6 +58,6 @@ const Homepage = () => (
5758
</Layout>
5859
);
5960

60-
identify('hero0420', 'B');
61+
identifyFromCookie('heroAB', 'hero0420');
6162

6263
export default Homepage;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { identify } from '@codesandbox/common/lib/utils/analytics';
2+
3+
function getCookie(name) {
4+
const pattern = RegExp(name + '=.[^;]*');
5+
const matched = document.cookie.match(pattern);
6+
if (matched) {
7+
const cookie = matched[0].split('=');
8+
return cookie[1];
9+
}
10+
return false;
11+
}
12+
13+
export function identifyFromCookie(cookie, identifyKey) {
14+
if (typeof document === 'undefined') {
15+
return;
16+
}
17+
18+
const cookieValue = getCookie(cookie);
19+
20+
if (cookieValue) {
21+
identify(identifyKey, cookieValue);
22+
}
23+
}

0 commit comments

Comments
 (0)