We build custom applications 5x faster and cheaper 🚀
Book a Free Consultation
Stuck on an error? Book a 30-minute call with an engineer and get a direct fix + next steps. No pressure, no commitment.
Use a Google service account (server-to-server) or OAuth client (user grants) to authenticate to Google Analytics, store those credentials securely in ClawHub as the skill’s secrets or environment variables, then implement an OpenClaw skill that calls the appropriate Google Analytics API (GA4 Data API for reporting, Measurement Protocol for event ingestion) with standard REST calls. Keep token-management and long-lived state outside the ephemeral agent runtime where needed (or use a secure secret store provided by ClawHub), validate API responses and scopes, and instrument detailed logging and retry/error handling so you can debug by inspecting API responses, logs, and credential scopes.
https://www.googleapis.com/auth/analytics.readonly (read) or https://www.googleapis.com/auth/analytics (read/write).
General pattern: your skill runtime obtains an access token (service account or OAuth refresh/access token), then issues REST calls to Google with Authorization: Bearer <ACCESS\_TOKEN>. Cache tokens until expiration; refresh as needed outside of the agent if persistence is required.
Example: GA4 Data API (report) via curl (replace placeholders):
curl -X POST "https://analyticsdata.googleapis.com/v1beta/properties/PROPERTY_ID:runReport" \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dimensions": [{"name":"country"},{"name":"city"}],
"metrics": [{"name":"activeUsers"}],
"dateRanges": [{"startDate":"2025-01-01","endDate":"2025-01-31"}]
}'
Example: GA4 Measurement Protocol (send an event) via curl:
curl -X POST "https://www.google-analytics.com/mp/collect?measurement_id=MEASUREMENT_ID&api_secret=API_SECRET" \
-H "Content-Type: application/json" \
-d '{
"client_id": "555",
"events": [{ "name": "purchase", "params": { "value": 9.99 } }]
}'
Node.js example using the official Google auth client to call the Data API (service account recommended for server-to-server). Install: npm install google-auth-library node-fetch@2. Replace environment variables and PROPERTY\_ID.
const { GoogleAuth } = require('google-auth-library');
const fetch = require('node-fetch');
async function runReport() {
const propertyId = process.env.GA4_PROPERTY_ID;
const auth = new GoogleAuth({
scopes: ['https://www.googleapis.com/auth/analytics.readonly'],
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
});
const client = await auth.getClient();
const url = `https://analyticsdata.googleapis.com/v1beta/properties/${propertyId}:runReport`;
const body = {
dimensions: [{ name: 'city' }],
metrics: [{ name: 'activeUsers' }],
dateRanges: [{ startDate: '2025-01-01', endDate: '2025-01-07' }]
};
const res = await client.request({ url, method: 'POST', data: body });
console.log(JSON.stringify(res.data, null, 2));
}
runReport().catch(err => {
console.error('report failed', err);
process.exit(1);
});
Speak one‑on‑one with a senior engineer about your no‑code app, migration goals, and budget. In just half an hour you’ll leave with clear, actionable next steps—no strings attached.
1
Most likely cause: the GA4 Measurement Protocol secret, measurement_id, or the collector endpoint/payload are misconfigured. Verify the API_SECRET and MEASUREMENT_ID used by your claw-collector, confirm the collector actually sends requests, and inspect GA4 responses (status and JSON error) — one of these is usually wrong.
Quick checks
curl -X POST "https://www.google-analytics.com/debug/mp/collect?measurement_id=MEASUREMENT_ID&api_secret=API_SECRET"
-H "Content-Type: application/json"
-d '{"client_id":"555","events":[{"name":"test_event"}]}' // validate response body for errors
2
Direct answer: Yes — double counts usually happen when OpenClaw’s batcher sends page_view or event hits while the page also loads gtag/auto-tracking. Fix by disabling gtag auto page_view or prevent the claw-batcher from sending duplicate event types; use event_id/client_id dedupe for server+client hits.
Check network for two /g/collect or /mp/collect requests. If both exist:
gtag('config','G-XXXX',{ 'send_page_view': false });// drop page_view events before send
events = events.filter(e => e.name !== 'page_view');
Inspect payloads for client_id and event_id. For GA4 Measurement Protocol include event_id so GA can dedupe server/client hits.
3
Capture the GA client_id (the value that becomes GA4’s user_pseudo_id) on the client, store a mapping OpenClaw user_id ↔ client_id in an external store, and send server-side GA4 Measurement Protocol v2 events that include both client_id and user_id. Including the original client_id preserves session stitching; user_id links cross-device identity.
Steps
// Node: GA4 Measurement Protocol v2
fetch('https://www.google-analytics.com/mp/collect?measurement_id=MEAS_ID&api_secret=SECRET',{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({
client_id:'GA_CLIENT_ID', // from client/_ga
user_id:'OPENCLAW_USER_ID',
events:[{name:'login',params:{session_id:Date.now()}}]
})
})
4
Yes. CORS, ad‑blockers, SameSite cookies and missing/altered claw‑proxy headers are common reasons Measurement Protocol (GA) hits are rejected or dropped. Fix by adding proper CORS response headers, sending hits server‑side to bypass blockers, setting cookies to SameSite=None; Secure, and ensuring any required proxy headers are preserved and validated.
Access-Control-Allow-Origin and Access-Control-Allow-Headers.SameSite=None; Secure when cross-site.// Node/Express CORS + cookie example
app.use((req,res,next)=>{
res.setHeader('Access-Control-Allow-Origin','https://your.site');
res.setHeader('Access-Control-Allow-Headers','Content-Type,Claw-Proxy');
next();
});
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â