Is it possible to track events by making direct HTTP calls to Google Analytics instead of using their standard JavaScript code? I want to create my own custom requests like https://analytics.google.com/track?account=UA-12345678-9&action=custom_action to send tracking information directly to their servers.
I need this because I’m working on a Xamarin Android app and can’t get the regular Google Analytics .NET libraries to work properly with the Xamarin framework. The standard libraries have dependencies that aren’t available in Xamarin Android.
Has anyone done something similar before? Are there any official APIs or endpoints that accept raw HTTP requests for analytics tracking? I’ve searched through their documentation but couldn’t find anything about manual URL-based tracking.
You’re looking at the wrong Analytics version. That sounds like old Universal Analytics, which is deprecated now. GA4 has the Measurement Protocol - you can send events directly to Google’s servers via HTTP requests.
I ran into the same thing with a Flutter project when the standard SDK wouldn’t play nice. Measurement Protocol uses POST requests to https://www.google-analytics.com/mp/collect with your measurement ID and API secret. Structure your payload as JSON with client_id and event data.
GA4’s Measurement Protocol docs are actually solid once you dig into their developer section. Just set up the API secret in your GA4 property first or your requests get rejected. Way more reliable than fighting with broken SDK versions.
yeah, totally doable but xamarin’s a pain with http client stuff. i used httpclient with the measurement protocol and it worked great. don’t forget the user-agent header though - google will reject requests without it. pro tip: batch multiple events in one post by separating them with newlines. saves network calls if you’re tracking tons of events.
Been down this exact road with a legacy .NET app that had the same SDK compatibility issues. Measurement Protocol is definitely your solution, but here’s the gotcha that got me - you need to validate your events are actually coming through since there’s no immediate feedback like with JavaScript implementation. I set up a test GA4 property first to mess around with the HTTP requests before touching production data. The client_id parameter is crucial - I generated UUIDs for each user session and kept them consistent across requests. Some events take a few hours to show up in GA4, so don’t freak out if you don’t see immediate results. The POST body structure is straightforward once you get it. Just make sure your content-type header is application/json and include the measurement_id in URL parameters with your api_secret.
Built something like this last year for server-side tracking to get around ad blockers.
The key with GA4 Measurement Protocol is proper validation. Use Google’s validation endpoint at https://www.google-analytics.com/debug/mp/collect - it gives you real error messages instead of failing silently.
For Xamarin, store the client_id in local storage so users stay consistent across sessions. Generate it once on first launch and keep using it.
Timestamps caught me off guard. If you’re not sending events right away, include timestamp_micros with when the event actually happened. Otherwise GA4 uses when it receives the request, which messes up your data if there’s any delay.
Watch your payload size too - GA4 limits how much data you can send per request. Found this out the hard way trying to batch too many events.
Manual HTTP requests work but you’re missing the bigger picture. Managing API calls, validation, error handling, and data formatting becomes a nightmare fast.
I’ve been there. Our mobile team needed custom analytics that bypassed standard SDKs. Yeah, you can build direct HTTP calls to GA4’s Measurement Protocol, but then you’re maintaining all that infrastructure yourself.
Automating the entire analytics pipeline saved us. Instead of hardcoding HTTP requests in Xamarin, route events through a workflow that handles validation, retry logic, batch processing, and multiple analytics destinations automatically.
Send simple webhook calls from your app while automation handles GA4 formatting, timestamps, and error recovery behind the scenes. You can easily add other analytics platforms later without touching mobile code.
Workflow approach beats managing raw HTTP calls in production. You get proper logging, monitoring, and can modify analytics logic without app updates.