-
Integrating Analytics for Discord Usage
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:
- 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!- 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.
- 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
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.
- Sending GET/POST requests to the
Log in to reply.