ins0 / google-measurement-php-client Goto Github PK
View Code? Open in Web Editor NEWPHP Client to send analytics data over the Google Measurement Protocol to Google Analytics
License: MIT License
PHP Client to send analytics data over the Google Measurement Protocol to Google Analytics
License: MIT License
i will add semantic versioning for a clean update possibility for non bc updates etc.
Hi,
Google Analytics recommends to use an rfc4122 UUID version 4 to identify the client.
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid
Although this unique identifier doesn't seem to be yet implemented by Google, they let users set their own client id field:
ga('create', 'UA-XXXXXXX-X', {
'clientId': '35009a79-1a05-49d7-b876-2b884d0f825b'
});
In order to be prepared for this future implementation and/or make your library compatible with developers that chose to set their own generated UUID, I think your createClientID
function should try to guess what kind of UUID is set in the GA cookie. The current release causes a notice (Undefined offset: 3) because the parsing part of the function is trying to get something that's not set:
$gaCookie = explode('.', $_COOKIE['_ga']);
$clientId = $gaCookie[2] . '.' . $gaCookie[3];
Here's the cookie exploded array when a developer client id is set:
Array
(
[0] => GA1
[1] => 1
[2] => 35009a79-1a05-49d7-b876-2b884d0f825b
)
Also, your library should let developers set the client ID if needed, createClientID
should only be used when the client id is not set. Measurement protocol is intended to enable server to server client tracking but there's currently no way to link/merge client side data (source, campaign, etc.) with data sent by the measurement protocol as the createClientID
will return an orphan UUID in a server to server request case.
Cheers,
N.
Hi
I think the need for a declaration in the following files:
Racecore/GATracking/Tracking/Ecommerce/Item.php
private $host = '';
Thanks for the useful library
Hi there,
We utilize this script to track events on the site. What we're seeing is that events are being tracked as sessions with the browser identified as "google-measurement-php-client". It's clear to me these aren't unique users, which is really what sessions are for in my experience. Is there a setting we can change so that events aren't recorded as sessions?
Thanks,
Craig
In no Internet available condition, the socket_connect call in Socket.php createConnection function throws the following error:
A PHP Error was encountered
Servetity: WarningMessage: socket_connect(): Host loockup failed [-10002]: Host name lookup failure
Filename: Adapter/Socket.phpLine Number: 32
Backtrace:
[...]
that ignoring the possible false return, and any exception throwing and try&catch.
Is there any way to avoid that error message in that specific call?
when more reports are send and one in stack failed, the other reports won't be send.
let me know when some users had a better idea then the current handling. thanks!
Hi in your class "page" for page view tracking missing User Parameters.
It's important for tracking user's navigation.
I'm currently refactoring the complete class, since the first release was working but not so well programmed.
Any suggestions would be very welcome :)
Tried to use the library in production (after testing in local development setup on Mac) and was receiving:
Class 'Racecore\GATracking\GATracking' not found
Basically, renaming the directory from "racecore" to "Racecore" in the src folder solved the problem.
Hi.
It would be wery userfull thing, if it was measuring the checkout process support.
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cos
Hi,
i've tried to use this php class to send a test pageview on my analytics account from the website.
You can see in the attached image the header, the content, and the response (the array).
Why I don't see the page view on my analytics account?
CLOSED: I didn't converted my account to Universal Analyicts :)
Hi,
I was using the 2.1.0 package successfully and my custom events were being sent properly.
Back on the 26th of April I updated to the latest version available (2.1.1) and since then the sending of events didn't work. We only noticed recently and it now all works again after downgrading.
The complete error message in my logs is:
socket_write(): unable to write to socket [32]: Broken pipe /home/xxx/xxx/vendor/ins0/google-measurement-php-client/src/Racecore/GATracking/Client /Adapter/Socket.php 62
I have looked around but I cannot find anything in particular so I'd appreciate it if someone could have a look.
check the dev branch feature-parameters
- i added all missing measurement parameters. this pre release should bc with the current release without the Campaign
class (dropped), these function is now embedded under all tracking types.
the example files are yet not updated. i need to restructure the hole tracking classes to allow maxium dynamically between all parameters and hit types.
please check it out and give a short comment here - thanks all
https://github.com/ins0/google-measurement-php-client/tree/feature-parameters
Hi, nice work. Do you plan to implement Enhanced Ecommerce (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#enhanced-ecomm)?
Hello!
First of all, thank you for this nice tool. I prefer it over other the alternatives because it is simple and lightweight. Well done!
Now, as for the issue: would it be possible to support in GMPC the IP override parameter? I am referring to the 'uip' parameter from https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uip.
A bit of context. I often set IP-based filters in my GA views. When I use GMPC, however, the IP sent to GA seems to be the server IP rather than the client IP.
If needed, I have written a function based on a Stack Overflow answer in order to extract the client IP; you can find the function here: https://gist.github.com/coccoinomane/4c420776dc16d80ea772aff06d3e1ef4
Thank you,
Guido
Hello, and thanks for your awesome project.
I would like to get responses and payloads for all the request made within a Multiple Tracking. Is there a way to get this?
Hi,
I'm using your library in a project I'm working on right now. Works perferctly. Thanks for sharing this !
I have a few questions about transaction/item parameters for ecommerce tracking.
After years of honoured service, the library is throwing this error:
[01-Jul-2019 09:21:16 UTC] PHP Fatal error: Uncaught Racecore\GATracking\Exception\EndpointServerException: Analytics Host not reachable! Error: Connection timed out in /home/meat/public_html/wp-content/plugins/wordpress-analytics/vendor/ins0/google-measurement-php-client/src/Racecore/GATracking/Client/Adapter/Socket.php:35
I first thought the problem was due to the GA-collect endpoint being hard-coded without HTTPS, but fixing that does not fix the error.
Does anybody have the same issue?
Cheers,
Guido
Hello.
When I trying to use sendMultipleTracking
from your example the code are hanging forever in
Racecore\GATracking\Client\Adapter\Socket@readConnection
method.
When I use simple sendTracking
it work correct. any ideas?
Hello,
with the new Universal Analytics code you have no more a "__umta" cookie but a single "_ga", so the current code for retrieving the Client ID from the cookie is wrong.
I've created a fork ( https://github.com/reysharks/google-measurement-php-client ) changing this behaviour and adding some Commerce Transaction features.
This is the code for retrieving the correct Analytics Client ID
list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1.'.'.$cid2);
$clientId = $contents['cid'];
Thank you for starting this project.
When I tried using the event tracking example, it doesn't seem to be picking up in GA.
The other elements seem to work.
Is there anything else we need to add?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.