jolly-journalist-68574
03/17/2023, 5:08 PMfew-electrician-23747
03/20/2023, 9:35 AMcuddly-journalist-11507
03/20/2023, 8:45 PMgb.loadFeatures().then(function() {
if (gb.isOn("widget") && variationId == 1) {
document.getElementById("gb_with-widget").style.display = 'flex'
document.getElementById("gb_no-widget").remove()
}
}
adventurous-lifeguard-80112
03/21/2023, 8:30 AMfreezing-apple-73992
03/21/2023, 1:08 PMfast-continent-33282
03/22/2023, 1:57 PMripe-boots-56746
03/22/2023, 2:05 PMdazzling-garden-98992
03/22/2023, 2:21 PMGBContext context = GBContext.builder()
.featuresJson(featuresJson)
.attributesJson(userAttributesObj.toString()) // Optional
.encryptionKey("****") // You may want to store this in an environment variable
.trackingCallback(trackingCallback)
.build();
GrowthBook growthBook = new GrowthBook(context);
But when I check https://github.com/growthbook/growthbook-kotlin , I see this:
var sdkInstance: GrowthBookSDK = GBSDKBuilderJAVA(apiKey = <API_KEY>,
hostURL = <GrowthBook_URL>,
attributes = <Hashmap>,
features = <Hashmap>,
trackingCallback = { gbExperiment, gbExperimentResult ->
}).initialize()
The sample from <http://app.growthbook.io|app.growthbook.io>
uses GBContext
and has no API key, while the github sample uses GBSDKBuilderJAVA
and requires an API key. Which is correct?miniature-agency-3305
03/22/2023, 2:53 PMdazzling-fountain-5777
03/23/2023, 7:47 PMprehistoric-oxygen-56976
03/24/2023, 10:19 AMhelpful-traffic-38691
03/27/2023, 9:58 AMfew-electrician-23747
03/27/2023, 10:26 AMfew-electrician-23747
03/27/2023, 10:32 AMfreezing-apple-73992
03/27/2023, 11:33 AMmysterious-nail-58688
03/27/2023, 6:04 PMbusy-air-96466
03/27/2023, 7:04 PMconst puppeteer = require('puppeteer');
const seedrandom = require('seedrandom');
const mainCTAProbabilities = {
freeControl: 0.3,
freeExperiment: 0.5,
paidControl: 0.6,
paidExperiment: 0.7,
};
const requestUrlParamsToJSON = requestURL => {
// Split request parameters and store as key-value object for easy access
let params = requestURL.split('?')[1];
return JSON.parse(
'{"' +
decodeURI(params)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}',
);
};
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
page
.on('console', message =>
console.log(
`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`,
),
)
.on('pageerror', ({ message }) => console.log(message))
.on('response', response =>
console.log(`${response.status()} ${response.url()}`),
)
.on('requestfailed', request =>
console.log(`${request.failure().errorText} ${request.url()}`),
);
await page.setRequestInterception(true);
page.on('request', req => {
const requestURL = req.url();
console.log('all url', requestURL);
if (requestURL.indexOf('<http://google-analytics.com/g/collect|google-analytics.com/g/collect>') > -1) {
console.log('Intercepted: ' + requestURL);
console.log('full req', requestUrlParamsToJSON(requestURL));
//req.abort();
req.continue();
} else {
req.continue();
}
});
await page.goto('<http://localhost:3000/>');
// Set screen size
await page.setViewport({ width: 1080, height: 1024 });
let userCount = 1;
const accountType = 'free';
const username = `${accountType}-puppeteer-${userCount}`;
// Enter username
await page.type('.username-input', username);
// Click login button
const loginButton = '.login-button';
await page.waitForSelector(loginButton);
await page.click(loginButton);
// Locate the main panel and read the title
console.log('logged in as', username);
const textSelector = await page.waitForSelector('.main-panel h2');
const panelTitle = await textSelector.evaluate(el => el.textContent);
// Print the full title
console.log('The panel title is "%s".', panelTitle);
// Decide whether to click the Main CTA button
// use a seeded random number generator to ensure the same user always makes the same decision
const encounterType =
panelTitle === 'Welcome (control)' ? 'Control' : 'Experiment';
const key = `${accountType}${encounterType}`;
const seededRandomNumberGenerator = seedrandom(username);
console.log('Key', key, mainCTAProbabilities[key]);
const dieRoll = seededRandomNumberGenerator();
const rollToClickCTA = dieRoll >= mainCTAProbabilities[key];
console.log('die roll', dieRoll);
if (rollToClickCTA) {
console.log('gonna click it');
const mainCTAButton = '#main-cta-button';
await page.waitForSelector(mainCTAButton);
await page.click(mainCTAButton);
console.log('clicked it!');
} else {
console.log('nah');
}
// logout
const logoutButton = '.logout-button';
await page.waitForSelector(logoutButton);
await page.click(logoutButton);
await browser.close();
})();
From the console output I can see that the dummy user logs in, and clicks the button. But no GA event is sent. But if I visit the page, login and click the button, the GA event is sent and shows up in BigQuery moments later.
Does anyone have any experience of using Puppeteer with Google Tag Manager? Any idea why itād be different in Headless Chrome? Many thanks for any ideas how to explore this problem!miniature-agency-3305
03/28/2023, 7:58 AMawait gb.loadFeatures({ autoRefresh: true });
Or would updating your attributes with setAttributes also retrigger an autorefresh in this scenario?few-electrician-23747
03/28/2023, 10:58 AMsticky-insurance-60813
03/28/2023, 7:46 PMbrash-stone-46387
03/29/2023, 1:16 AMThe GrowthBook config has been written at ~/.growthbook/config.toml
But running the line to generate types returns an Unauthorised error:
There was an error fetching the featuresError: Cannot fetch: Unauthorized
Did anyone experience the same?helpful-traffic-38691
03/29/2023, 6:46 AMsticky-insurance-60813
03/29/2023, 4:28 PMsticky-insurance-60813
03/29/2023, 9:41 PMthousands-insurance-50391
03/30/2023, 4:35 AMswift-lifeguard-19355
03/30/2023, 8:08 AMquick-motorcycle-91655
03/30/2023, 10:34 AMfamous-belgium-62991
03/30/2023, 1:52 PMfamous-belgium-62991
03/30/2023, 1:56 PMfamous-belgium-62991
03/30/2023, 2:02 PM