Skip to content

Commit

Permalink
💩 Use setImmediate to delay exp id setting
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Aug 3, 2023
1 parent 3ab7224 commit b7f77e9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/plugins/experiment.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ export default ({ app }) => {
const { experimentID, $variantIndexes } = app.$exp;
if (!experimentID || !$variantIndexes || !$variantIndexes.length) return;
if (app.$gtag && window && window.gtag) {
app.$gtag.set({
experiments: [{ id: experimentID, variant: $variantIndexes.join('-') }],
});
app.$gtag.event('experiment_impression', {
experiment_id: experimentID,
variant_id: `${experimentID}.${$variantIndexes.join('-')}`,
setImmediate(() => {
// HACK: Wait for gtag config GTM ID before sending exp
app.$gtag.set({
experiments: [
{ id: experimentID, variant: $variantIndexes.join('-') },
],
});
app.$gtag.event('experiment_impression', {
experiment_id: experimentID,
variant_id: `${experimentID}.${$variantIndexes.join('-')}`,
});
});
}
}
Expand Down

0 comments on commit b7f77e9

Please sign in to comment.