ApollosProject / apollos-embeds

Apollos React Embeds that can be used in Webflow and other third-party websites.
https://www.npmjs.com/package/@apollosproject/apollos-embeds
0 stars 0 forks source link

Feat:Added bot detection and disabled analytics if a bot #227

Closed rajitharussel closed 3 months ago

rajitharussel commented 4 months ago

🐛 Issue

Closes #226

✏️ Solution

implemented way to identify bots and disbled logs.

🔬 To Test

  1. I build this snippet to load the page as a bot. and added some logs here so we can check if analytics are executed.
const puppeteer = require('puppeteer');

async function scrapeData(url) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    // Listen for all console events and log them
    page.on('console', msg => {
        console.log('CONSOLE:', msg.text());
    });
    await page.goto(url, { waitUntil: 'networkidle0' });  // Ensures the page has loaded completely

    // Extract data
    const data = await page.evaluate(() => {
        const element = document.querySelector('.apollos-widget');
        return element ? element.innerText : null;
    });

    await browser.close();
    return data;
}

scrapeData('http://localhost:3000/ac/the-rest-of-god-TWVkaWFDb250ZW50SXRlbS02MGQ0Njg0YS03NWQ2LTQ2MzAtYTJjOC1iMDI0MWZkMTE5NzQ=').then(console.log).catch(console.error);

to see if analytics executed add followings here

https://github.com/ApollosProject/apollos-embeds/blob/5adf7e6b1d4d8efb8553a2320e0331350b348549/packages/web-shared/analytics/amplitude.js#L3

Screenshot 2024-07-04 at 17 43 14

  1. or can use analytics realtime dashboard directly

📸 Screenshots

Before

Screenshot 2024-07-04 at 17 47 42

After

Screenshot 2024-07-04 at 17 48 17

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
apollos-micro-service ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 9:38am
apollos-web-embeds ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 9:38am