-
Notifications
You must be signed in to change notification settings - Fork 2
Adding Google Analytics
Foxx Builder comes with some utilities that can help you with extending your API functionality, one of them is ga.js - a Google Analytics client; you can add it to your API router in the following way:
module.context.use((req, _res, next) =>
{
const {runTask} = module.context;
runTask(
'Google Analytics PageView recording',
'ga',
{
clientId: req.headers['x-user-id'],
path: req.path,
headers: req.headers
});
next();
});It runs as ArangoDB tasks via runTask utility accessible within module.context and depends on googleAnalyticsId variable from your manifest.json file configuration section:
{
"configuration": {
"googleAnalyticsId": {
"default": "G-Y32FMJEM1W",
"type": "string",
"description": "Google Analytics Measurement ID"
}
}
}You can set googleAnalyticsId value in manifest.json directly or via web interface if it is accessible.
The minimal required payload for qa.js task is the path - request path, and the headers - request headers that will be used to extract the request IP address and User-Agent.
This feature is available as an example in feat/google-analytics branch: https://github.com/skitsanos/foxx-builder/tree/feat/google-analytics
Copyright © 2016-2025, Skitsanos™