Code Monkey home page Code Monkey logo

google-analytics-cookie-parser-php's Introduction

Google-Analytics-Cookie-Parser-PHP

Build Status

This tool converts google's utmz and utma cookies into easy to use objects.

This gives easy access to googel session and keyword data.

#Installation Install via composer. Edit your project's composer.json file to require jflight/gacookie:

"require": {
	"jflight/gacookie":"dev-master"
}

Update Composer from the terminal:

composer update

#Usage Parse the cookies (currently supports utma and utmz):

<?php

use Jflight\GACookie\GACookie;

$utma = GACookie::parse('utma');
$utmz = GACookie::parse('utmz');

Or directly parse strings:

<?php

$utma = GACookie::parseString('utma', '177910838.254655113.1474876189.1482142331.1482148790.58');
$utmz = GACookie::parseString('utmz', '177910838.1481550491.52.15.utmcsr=newsletter|utmccn=campaign-2016|utmcmd=email');

You can now access cookie variables:

For utma

<?php

$utma->time_of_first_visit; // DateTime
$utma->time_of_last_visit; // DateTime
$utma->time_of_current_visit; // DateTime
$utma->session_count // Integer

For utmz

<?php

$utmz->timestamp; // DateTime
$utmz->session_count // Integer
$utmz->campaign_number // Integer
$utmz->source // string
$utmz->medium // string
$utmz->campaign // string
$utmz->term // string
$utmz->content // string

Because all time related properites return DateTime objects, this sort of thing is possible:

<?php

echo $utma->time_of_first_visit->format('Y'); // e.g. 2014

Also if you are so inclined, properties can be accessed via ArrayAccess:

<?php

echo $utmz['source']; // e.g. google

google-analytics-cookie-parser-php's People

Contributors

clemlatz avatar jamesflight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

google-analytics-cookie-parser-php's Issues

Show time as per give time zone

Is there any way to get the all time variable as per time zone?

currently it working with Standard world UTC time . But need this to be as depend of given country time zone

Parsing utmz from a string instead of reading a cookie

Hi,

I'm a working on an ecommerce application. Whenever a new order is created by a customer, it stores the value of the utmz cookie in a field of the database along with the order. I'd like to use your library to parse that field and extract the source, campaign and medium parameters from the raw string.

As I understand it, the library directly reads from the cookies sent with the request. Would it be complicated to modify it so could also parse a string that was previously saved? Something like:

$utmz = GACookie::parseString('utmz', '177910838.1481550491.52.15.utmcsr=newsletter|utmccn=campaign-2016|utmcmd=email');

Thanks,

Clément

Trouble with dot in utm_source value

Hello!
I'm trying to use your nice library and found some error: if utmcsr field in utmz cookie contain full URL with dots $utmz->source set to first part of it only.

Ex. __utmz = 256315294.1404213711.4.4.utmcsr=sp.tomica.ru|utmccn=201407-waist|utmcmd=banner|utmcct=banner $utmz->source // sp
Quick fix - add limit (5) as third param to explode in Utmz.php:83 $cookieBits = explode('.', $cookie, 5);

Deprecation notices

Hi @jamesflight ,

I'm seeing some deprecations notices that I think could be resolved by a dependency update.

Deprecated: Method ReflectionParameter::getClass() is deprecated in vendor/illuminate/container/Illuminate/Container/Container.php on line 608

Are you still maintaining this library? Would you accept a pull request?

Thanks,

Clément

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.