Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
d3517cc3
Commit
d3517cc3
authored
Jan 11, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip ci] send "Experiment started" event only once
parent
f5ccadf0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
init.ts
lib/growthbook/init.ts
+37
-0
No files found.
lib/growthbook/init.ts
View file @
d3517cc3
...
@@ -23,6 +23,11 @@ export const growthBook = (() => {
...
@@ -23,6 +23,11 @@ export const growthBook = (() => {
chain_id
:
config
.
chain
.
id
,
chain_id
:
config
.
chain
.
id
,
},
},
trackingCallback
:
(
experiment
,
result
)
=>
{
trackingCallback
:
(
experiment
,
result
)
=>
{
if
(
isExperimentStarted
(
experiment
.
key
))
{
return
;
}
saveExperimentInStorage
(
experiment
.
key
);
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
EXPERIMENT_STARTED
,
{
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
EXPERIMENT_STARTED
,
{
'
Experiment name
'
:
experiment
.
key
,
'
Experiment name
'
:
experiment
.
key
,
'
Variant name
'
:
result
.
value
,
'
Variant name
'
:
result
.
value
,
...
@@ -31,3 +36,35 @@ export const growthBook = (() => {
...
@@ -31,3 +36,35 @@ export const growthBook = (() => {
},
},
});
});
})();
})();
const
STORAGE_KEY
=
'
growthbook:experiments
'
;
const
STORAGE_LIMIT
=
20
;
function
getStorageValue
():
Array
<
unknown
>
|
undefined
{
const
item
=
window
.
localStorage
.
getItem
(
STORAGE_KEY
);
if
(
!
item
)
{
return
;
}
try
{
const
parsedValue
=
JSON
.
parse
(
item
);
if
(
Array
.
isArray
(
parsedValue
))
{
return
parsedValue
;
}
}
catch
{
return
;
}
}
function
isExperimentStarted
(
key
:
string
):
boolean
{
const
items
=
getStorageValue
()
??
[];
return
items
.
some
((
item
)
=>
item
===
key
);
}
function
saveExperimentInStorage
(
key
:
string
)
{
const
items
=
getStorageValue
()
??
[];
const
newItems
=
[
key
,
...
items
].
slice
(
0
,
STORAGE_LIMIT
);
try
{
window
.
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
newItems
));
}
catch
(
error
)
{}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment