admin管理员组文章数量:1430478
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 poser.
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 e across any kind of this library?
Found this one very helpful
/
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 poser.
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 e across any kind of this library?
Found this one very helpful
https://gearside./using-server-side-google-analytics-sending-pageviews-event-tracking/
Share Improve this question edited Apr 19, 2018 at 9:14 Test asked Apr 19, 2018 at 8:20 TestTest 631 silver badge8 bronze badges2 Answers
Reset to default 2The 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.
Using
https://github./thomasbachem/php-ga
Install via
poser require united-prototype/php-ga
Below is the code
use UnitedPrototype\GoogleAnalytics;
$tracker = new GoogleAnalytics\Tracker('UA-XXXXXX-1', 'example.');
$session = new GoogleAnalytics\Session();
// Setup visitor
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress($server->get('REMOTE_ADDRESS'));
$visitor->setUserAgent($server->get('HTTP_USER_AGENT'));
//Set Event
$event = new GoogleAnalytics\Event();
$event->setCategory('Category'); // Event Category (Required)
$event->setAction('Event'); // Event Action (Required)
$event->setLabel('Label'); // Event Label (Optional)
$event->setValue(1); //integer, not required
//track event
$response = $tracker->trackEvent($event,$session,$visitor);
Works fine for me.
本文标签: javascriptHow to add Google Analytics Event via PHPStack Overflow
版权声明:本文标题:javascript - How to add Google Analytics Event via PHP? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745497701a2660882.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论