breezy-king-73167
05/05/2023, 5:22 AMfresh-football-47124
breezy-king-73167
05/05/2023, 6:08 AMripe-answer-39685
05/17/2023, 12:46 AMbreezy-king-73167
05/17/2023, 12:55 AMawait gb.loadFeatures({ autoRefresh: true });
ripe-answer-39685
05/17/2023, 12:55 AMbreezy-king-73167
05/17/2023, 1:05 AMimport { GrowthBook } from '@growthbook/growthbook'
export default ({ env }, inject) => {
let growthBook = null
/**
* For initializing Growthbook
* @returns (null/Growthbook) Returns GrowthBook or null
*/
const initGrowthBook = async function () {
/* Prevent reinitializing Growthbook */
if (growthBook) {
return growthBook
}
/* Initialize Growthbook */
growthBook = new GrowthBook({
apiHost: env.GROWTHBOOK_API_HOST,
clientKey: env.GROWTHBOOK_API_KEY,
enableDevMode: env.NODE_ENV === 'development',
trackingCallback: (experiment, result) => {
// track using GA4
if ("gtag" in window) {
this.$gtag.query("event", "experiment_viewed", {
event_category: "experiment",
experiment_id: experiment.key,
variation_id: result.variationId,
})
} else {
console.warn("no gtag")
}
}
})
//Set user attributes
await this.$gtag.query('get', env.GA4_TRACKING_ID, 'client_id', (client_id)=>{
growthBook.setAttributes({
country: 'france',
id: client_id,
})
})
/* Load Growthbook features */
try {
await growthBook.loadFeatures({
autoRefresh: true,
timeout: 2000,
})
return growthBook
} catch (error) {
console.error('Failed to load features from GrowthBook', error)
return null
}
}
inject('initGrowthBook', initGrowthBook)
fresh-football-47124
breezy-king-73167
05/22/2023, 2:30 AMfresh-football-47124
breezy-king-73167
05/22/2023, 10:16 PMaloof-easter-14325
07/04/2023, 9:19 AMloadFeatures
is not a function, did you ever experience it?