Skip to content

Commit 2f64c49

Browse files
committed
Actually send events to vero
1 parent cac442b commit 2f64c49

File tree

1 file changed

+33
-20
lines changed
  • packages/common/src/utils/analytics

1 file changed

+33
-20
lines changed

packages/common/src/utils/analytics/vero.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ export const trackPageview = () => {
1414
// Already start tracking the first pageview
1515
trackPageview();
1616

17+
/**
18+
* For some reason vero doesn't call it, so we do it for them.
19+
*/
20+
function processArray() {
21+
if (
22+
typeof global.__vero !== 'undefined' &&
23+
typeof global.__vero.processVeroArray === 'function'
24+
) {
25+
global.__vero.processVeroArray(_veroq);
26+
}
27+
}
28+
1729
function loadScript() {
1830
return new Promise((resolve, reject) => {
1931
const script = document.createElement('script');
@@ -22,6 +34,8 @@ function loadScript() {
2234
script.onerror = reject;
2335
script.src = '//d3qxef4rp70elm.cloudfront.net/m.js';
2436
document.body.appendChild(script);
37+
}).then(() => {
38+
processArray();
2539
});
2640
}
2741

@@ -34,35 +48,34 @@ export const setAnonymousUserId = (userId: string) => {
3448

3549
_hasSetAnonymousUserId = true;
3650

37-
_script.then(() => {
38-
_veroq.push([
39-
'user',
40-
{
41-
id: userId,
42-
},
43-
]);
44-
});
51+
_veroq.push([
52+
'user',
53+
{
54+
id: userId,
55+
},
56+
]);
57+
processArray();
4558
};
4659

4760
export const setUserId = (userId: string) => {
4861
if (!_script) {
4962
_script = loadScript();
5063
}
5164

52-
_script.then(() => {
53-
if (_hasSetAnonymousUserId) {
54-
_veroq.push([
55-
'user',
56-
{
57-
id: userId,
58-
},
59-
]);
60-
} else {
61-
_veroq.push(['reidentify', userId]);
62-
}
63-
});
65+
if (_hasSetAnonymousUserId) {
66+
_veroq.push([
67+
'user',
68+
{
69+
id: userId,
70+
},
71+
]);
72+
} else {
73+
_veroq.push(['reidentify', userId]);
74+
}
75+
processArray();
6476
};
6577

6678
export const track = (eventName: string, data: unknown) => {
6779
_veroq.push(['track', eventName, data]);
80+
processArray();
6881
};

0 commit comments

Comments
 (0)