forked from statsig-io/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatsig.js
More file actions
54 lines (47 loc) · 1.42 KB
/
statsig.js
File metadata and controls
54 lines (47 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
// TODO - currently over logs for menus with sub links
function wireClickHandlers(tagName) {
const elements = document.getElementsByTagName(tagName);
for (let ii = 0; ii < elements.length; ii++) {
const el = elements[ii];
el.addEventListener("click", () => {
window.statsig.logEvent({}, "link_click", el.pathname, {
page: window.location.href,
referrer: document && document.referrer,
});
});
}
}
export default (function () {
if (!ExecutionEnvironment.canUseDOM) {
return null;
}
return {
onRouteUpdate({ location }) {
if (
typeof window === "undefined" ||
typeof window.statsig === "undefined"
) {
return;
}
try {
window.statsig.initialize(
"client-LAx5juseYG9kxnB2vHLxFluaFmZVv9aAKPmw1NB8rps",
{
environment: { tier: window.statsigTier },
initializeValues: window.statsigConfigSpecs,
}
);
const statsig = window.statsig;
statsig.getExperiment({}, "a_a_test");
const layer = statsig.getLayer({}, "master_layer");
layer.get("title", "code_default");
window.statsig.logEvent({}, "page_view", window.location.pathname, {
referrer: document && document.referrer,
});
} catch (e) {
console.error(e);
}
},
};
})();