Hiya, I am trying to use Puppeteer to auto-generate data for my GrowthBook demo. My puppeteer script...
s

Shelagh Lewins

over 2 years ago
Hiya, I am trying to use Puppeteer to auto-generate data for my GrowthBook demo. My puppeteer script appears to work perfectly but none of the GA events (defined with GTM) are firing, except the initial page_view. I’ve googled but can’t find any reason why the GA events would work when I visit the page and perform actions manually, but not when Puppeteer does the same thing? I’m running a React app locally on port 3000, and GrowthBook locally on port 4000. GA events from Puppeteer are not showing up in BigQuery, and when I intercept requests, it appears that they are not being sent. Forgive me if this question is too out-of-scope; I realise there’s no fault in GrowthBook, I’m just out of ideas! Here’s my Puppeteer script:
const 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!
Hi Everyone , Need small help. I have installed growthbook on kubernetes . Deployment is up and runn...
k

Kuldeep Singh

about 2 years ago
Hi Everyone , Need small help. I have installed growthbook on kubernetes . Deployment is up and running but i can see below error in pod logs. Could you please help.
yarn run v1.22.19
$ wsrun -p 'back-end' -p 'front-end' --no-prefix -c start
$ node dist/server.js
$ next start
ready - started server on 0.0.0.0:3000, url: <http://localhost:3000>
{"level":30,"time":1697208604637,"pid":58,"hostname":"growthbook-74486f46c4-w9htb","msg":"No config.yml file. Using MongoDB instead to store data sources, metrics, and dimensions."}
(node:58) [MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7. Use `mongoose.set('strictQuery', false);` if you want to prepare for this change. Or use `mongoose.set('strictQuery', true);` to suppress this warning.
(Use `node --trace-deprecation ...` to show where the warning was created)
{"level":30,"time":1697208608604,"pid":58,"hostname":"growthbook-74486f46c4-w9htb","msg":"Back-end is running at <http://localhost:3100> in development mode. Press CTRL-C to stop"}
{"level":40,"time":1697208638541,"pid":58,"hostname":"growthbook-74486f46c4-w9htb","err":{"type":"MongooseServerSelectionError","message":"connect ECONNREFUSED 127.0.0.1:27017","stack":"MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017\n    at NativeConnection.Connection.openUri (/usr/local/src/app/node_modules/mongoose/lib/connection.js:825:32)\n    at /usr/local/src/app/node_modules/mongoose/lib/index.js:414:10\n    at /usr/local/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5\n    at Promise._execute (/usr/local/src/app/node_modules/bluebird/js/release/debuggability.js:384:9)\n    at Promise._resolveFromExecutor (/usr/local/src/app/node_modules/bluebird/js/release/promise.js:518:18)\n    at new Promise (/usr/local/src/app/node_modules/bluebird/js/release/promise.js:103:10)\n    at promiseOrCallback (/usr/local/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)\n    at Mongoose._promiseOrCallback (/usr/local/src/app/node_modules/mongoose/lib/index.js:1288:10)\n    at Mongoose.connect (/usr/local/src/app/node_modules/mongoose/lib/index.js:413:20)\n    at /usr/local/src/app/packages/back-end/dist/init/mongo.js:34:34\n    at Generator.next (<anonymous>)\n    at /usr/local/src/app/packages/back-end/dist/init/mongo.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/usr/local/src/app/packages/back-end/dist/init/mongo.js:4:12)\n    at exports.default (/usr/local/src/app/packages/back-end/dist/init/mongo.js:21:25)\n    at /usr/local/src/app/packages/back-end/dist/init/index.js:25:43","reason":{"type":"Unknown","servers":{},"stale":false,"compatible":true,"heartbeatFrequencyMS":10000,"localThresholdMS":15,"setName":null,"maxElectionId":null,"maxSetVersion":null,"commonWireVersion":0,"logicalSessionTimeoutMinutes":null}},"msg":"Failed to connect to MongoDB. Retrying with field remapping for mongodb v3 to v4"}
{"level":50,"time":1697208668549,"pid":58,"hostname":"growthbook-74486f46c4-w9htb","err":{"type":"MongooseServerSelectionError","message":"connect ECONNREFUSED 127.0.0.1:27017","stack":"MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017\n    at NativeConnection.Connection.openUri (/usr/local/src/app/node_modules/mongoose/lib/connection.js:825:32)\n    at /usr/local/src/app/node_modules/mongoose/lib/index.js:414:10\n    at /usr/local/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5\n    at Promise._execute (/usr/local/src/app/node_modules/bluebird/js/release/debuggability.js:384:9)\n    at Promise._resolveFromExecutor (/usr/local/src/app/node_modules/bluebird/js/release/promise.js:518:18)\n    at new Promise (/usr/local/src/app/node_modules/bluebird/js/release/promise.js:103:10)\n    at promiseOrCallback (/usr/local/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)\n    at Mongoose._promiseOrCallback (/usr/local/src/app/node_modules/mongoose/lib/index.js:1288:10)\n    at Mongoose.connect (/usr/local/src/app/node_modules/mongoose/lib/index.js:413:20)\n    at /usr/local/src/app/packages/back-end/dist/init/mongo.js:50:38\n    at Generator.throw (<anonymous>)\n    at rejected (/usr/local/src/app/packages/back-end/dist/init/mongo.js:6:65)","reason":{"type":"Unknown","servers":{},"stale":false,"compatible":true,"heartbeatFrequencyMS":10000,"localThresholdMS":15,"setName":null,"maxElectionId":null,"maxSetVersion":null,"commonWireVersion":0,"logicalSessionTimeoutMinutes":null}},"msg":"Failed to connect to MongoDB after retrying"}
{"level":50,"time":1697208668550,"pid":58,"hostname":"growthbook-74486f46c4-w9htb","err":{"type":"Error","message":"MongoDB connection error.","stack":"Error: MongoDB connection error.\n    at /usr/local/src/app/packages/back-end/dist/init/mongo.js:54:19\n    at Generator.throw (<anonymous>)\n    at rejected (/usr/local/src/app/packages/back-end/dist/init/mongo.js:6:65)"},"msg":"Failed to initialize application"}
error Command failed with exit code 1.
info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.
`yarn start` failed with exit code 1