theiconic / php-ga-measurement-protocol

Send data to Google Analytics from the server using PHP. Implements GA measurement protocol.
MIT License
656 stars 135 forks source link

Get parameters [new feature] #18

Closed Nightbr closed 8 years ago

Nightbr commented 8 years ago

Hello, after looking at the code, there is no public function to get parameters from Analytics Object. It can be usefull in some case to be able to get parameters from Analytics Object.

Example, I have a factory which creates the Analytics Object and put automatically the clientId if there is a _ga cookie. But in some case, there is not _ga cookie so I work with the userId. I would like to test if my Analytics object has the property clientId set otherwise I put my userId into the clientId (because clientId doesn't exist...).

I think we can find a lots of cases which requires to be able to get parameters.

Thanks in advance!

stefanzweifel commented 8 years ago

+1 for this!

In my usecase I would like to use the Email Tracking Feature of Analytics. I first considered building my own package, but if the value on this line would be available on the Analytics Object I could just use your package 😃

jorgeborges commented 8 years ago

@Nightbr I just merged @stefanzweifel PR to get the URL at any time from the Analytics object.

This may not be enough for you tho, since you probably want to get all current parameters in a nice array or something?

Nightbr commented 8 years ago

Hey, thanks for the update. It's a nice feature to retrieve the URL form the Analytics Object but for my case I have to parse the URL to see if there is the value I am looking for...

I will look If I have time to implement simple Getter for all parameters from Analytics Object. For example:

// Get any parameter by its name
// Look at the parameter names in Google official docs at
// https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
$analytics->get<ParameterName>();
Nightbr commented 8 years ago

Hey, I just made a pull requests ;) Feel free to ask me anything about it before merge it.

Enjoy the power of Getter!!

Nightbr commented 8 years ago

thanks for the merge ;) Waiting for a version tag ^^

jorgeborges commented 8 years ago

@Nightbr Thank you for the contribution, I'll tag and release this weekend!