Use google analytics on endpoint

javascript
#1

So i have these endpoints on my site, which aren’t HTML pages, they’re built like:

app.get(’/api/v1/panda/fact’, function (request, response) {
const db = require(’./db/panfacts.json’)
let fact = db[Math.floor(Math.random() * 36)].fact;
let entry = db[Math.floor(Math.random() * 36)].entry;
response.send({“object”: {“entry”:entry, “fact”:fact},});
});

So, how would i be able to add something so google analytics can collect data on this?

#2

Hey @SammyWhamy someone else might have direct experience they can share, but you might find it useful to look at https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide or perhaps the universal-analytics package as places to start.

Let us know how it goes!