Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

codefreak's avatar

Use Google Analytics with API built with laravel.

Anybody have experience to use Google analytics with API built with laravel?

I created API for my site. Now I want to track API usage with the help Google Analytics.

Thanks in advance.

0 likes
6 replies
milon's avatar

I also need this. following.

2 likes
theUnforgiven's avatar

Snap, I'd like to see how to integrate Analytics into a site/admin system

2 likes
bashy's avatar

That's the other way around by using the Google API :P

They want to track activity on their own API using GA

livingos's avatar

There are various packages for sending analytics to GA using the measurement protocol, e.g. https://github.com/irazasyed/laravel-gamp - a wrapper for https://github.com/theiconic/php-ga-measurement-protocol

Check out the async option too, on this one. You don't want your API users waiting for Google! If you use GA on your web views, it is all done async in JavaScript. Once you start doing this in your API backend, you need to consider the performance hit.

Another alternative might be too look at https://piwik.org/

But sounds like you want to build some kind of front end for the analytics too. For one of my projects I just created a table and middleware to log client_id, end point, ip address etc for each call on api. This allows for some basic analytics and management of api.

Please or to participate in this conversation.