Learn business growth with Google Analytics 4 Forums Google Analytics 4 Integrating Analytics for Discord Usage

  • Integrating Analytics for Discord Usage

    Posted by Mia on 12 November 2022 at 8:39 am

    Need a hand with Google Analytics and my Discord bot

    Hey guys! After quite a bit of tinkering, I’ve finally managed to host my own Discord bot, and I’m running a node server on my localhost. It’s super cool—I can do so much with my Discord bot.

    Now, because I’m a bit of an analytics nerd, I’ve been trying to figure out how to send data to Google Analytics (specifically GA4) from this node server.

    Just a heads-up: I did manage to send data to my Universal Analytics property, which was a rush! But then I remembered that Google’s closing down Universal Analytics this July—a real bummer.

    I’ve tried a few things:

    1. Sending GET/POST requests to the collect endpoint

    This seemed like a no-go right from the start. To send a request, I’d need a client_id, which apparently has to be generated using Google’s client id algorithm. So, making one up isn’t an option. If you’ve had success with this, I’d love to hear about it!

    1. Installing the googleapis npm package

    Initially, I thought this would be an easy win, but no joy. This package only lets me read data, not send anything to GA.

    1. Scouting for and installing a GTM npm package

    There are GTM npm packages out there, but all the ones I found seem to need a window object. Unfortunately, my node server doesn’t have that luxury since it’s not a browser.

    This is what worked for Universal Analytics

    Just to clarify, my aim here is to do all this just using NodeJS, without having to get into Python, Java, C++ or any of those other languages. I’d really rather not add ‘learn another language’ to my to-do list!

    Anyway, I came up with a sort of workaround for Universal Analytics—I created a webpage, which then acted as a go-between, passing on data to GA when accessed by something like a page scraper. It was pretty simple. I just set up an HTML file with Google Tag Manager, and then used the puppeteer npm package.

    It’s not ideal, but it gets the job done. Plus, Google Tag Manager being able to handle and tweak input is a bonus.

    Here’s the kicker, though: The same method won’t work for GA4. It automatically rules out all bot traffic, and there’s no way around it. I get why it’s a great feature for GA4. I mean, it makes everything so much more robust compared to UA. It’s just frustrating since it’s also blocking me from achieving my goal.

    https://support.google.com/analytics/answer/9888366?hl=en

    GA4 says "no"

    What’s next?

    I’m pretty much at my wits end here, so maybe there’s an npm package out there that I’ve missed or am I barking up the wrong tree?

    Have any one of you awesome folks had any luck with sending data from NodeJS to GA4 (or even GTM)? if yes, please spill the beans.

    Owen replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Lucas

    Member
    17 May 2023 at 2:33 pm

    Hey! Just so you know, you actually can create a client_id. GA4 generates it in a similar way to UA – you don’t need anything from Google to make it.

    You could also try going straight for the Measurement Protocol: https://developers.google.com/analytics/devguides/collection/protocol/ga4. The links given by @dockeryZ might work better if you open them in an incognito window or a different browser.

    Plus, there’s no need to build everything from scratch. Node already has some packages for sending events to GA4. Here’s a good one as an example: https://www.npmjs.com/package/ga4-mp?activeTab=readme.

    And lastly, if you’re worried about Google’s bot traffic detection, don’t be! It’s not exactly sophisticated. As long as your user agent doesn’t blatantly say “bot”, you should be fine. Just be creative with it. Hope this helps!

  • Owen

    Member
    21 May 2023 at 9:32 pm

    The user is seeking assistance in sending data from a locally hosted NodeJS server running a Discord bot, to Google Analytics 4 (GA4). Previous attempts, including sending GET/POST requests to collect endpoints, using the googleapis npm package, and using Google Tag Manager, were unsuccessful. The method used for Universal Analytics is not applicable for GA4 due to its restriction on bot traffic. The user is asking for advice on any potential npm package or other method for data transfer to GA4 using NodeJS.

Log in to reply.