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 7f0818f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/plugins/experiment.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ 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 7f0818f

Please sign in to comment.