Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Google Analytics Event via PHP?

GA Events in Javascript we can do by

ga('send', 'event', 'test', 'test','value');

I need to implement this in entire project. But there are some sections where I need to do it via PHP.

So looking for PHP library that can be added as a module via composer.

I found

Google Analytics Measurement Protocol library for PHP

PHP Analytics Events

But this one is not best. That which I'm looking for.

Tracking Id & Website only specified by once. Then just need to pass event parameters as we do in Javascript.

Does anyone come across any kind of this library?

Found this one very helpful

https://gearside.com/using-server-side-google-analytics-sending-pageviews-event-tracking/

like image 347
Test Avatar asked Jan 16 '26 19:01

Test


1 Answers

The Google analytics javascript snippet sends data to google analytics via the measurment protocol

The measurement protocol accepts http post and http gets. This can easly be done with PHP but if you are looking for something out of the box created to do it there isnt anything official written in php that i am aware of. Your going to have to code this yourself.

like image 168
DaImTo Avatar answered Jan 19 '26 09:01

DaImTo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!