Giter Site home page Giter Site logo

avbranco / ga_cookie_parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simonrobson/ga_cookie_parser

0.0 1.0 0.0 184 KB

Ruby parser for Google Analytics utmz and utma cookies

Home Page: https://github.com/simonrobson/ga_cookie_parser

License: MIT License

ga_cookie_parser's Introduction

Google Analytics Cookie Parser

Simple ruby library for parsing the __umtz, __umtb and __umta cookies which Google Analytics uses to track referrers and visitors.

You may wish to use this library to integrate data from Google Analytics into your internal CRM or sales tracking application.

Installation

The library is available as a gem.

gem install ga_cookie_parser

Usage

Create an instance, or use the convenience method GaCookieParser.parse, providing a hash with keys :umtz and/or :umtz as argument.

utmz = cookies["__utmz"] # in a rails controller context
utmb = cookies["__utmb"]
utma = cookies["__utma"]
@data = GaCookieParser::GaCookieParser.new(:utmz => utmz, :utmb => utmb, :utma => utma)

Then, @data provides #utmz_hash, #utmb_hash and #utma_hash methods which return hashes as follows:

# @data.utmz_hash
# note that not all of these will be present, and some are mutually exclusive
{
  :domain_hash => '12979384',
  :timestamp   => '1294887021',  # unix timestamp
  :session_counter => '1',
  :campaign_number => '1',
  :utmcsr => 'google',       # source
  :utmccn => '(organic)',      # campaign name
  :utmcmd => 'organic',      # medium
  :utmctr => 'search term',    # term(s)
  :utmcct => '/ref.php,      # content (referring page in case of referrals)
  :utmgclid => 'CI7wh8C6tKYCFU2DpAod7z97IQ'  # gclid, linking referral back to adwords
}

# @data.utma_hash
{
  :domain_hash => '12979384',
  :visitor_id =>  '1392679796',    # a random number
  :initial_visit_at =>  '1289844797',  # unix timestamp
  :previous_visit_at => '1294798990',  # unix timestamp
  :current_visit_at => '1294866800',  # unix timestamp
  :session_counter => '1' 
}

# @data.utmb_hash
{
  :domain_hash => '12979384',
  :pageview =>  '3',    # pageview count in this 30 min session
  :outbound_click =>  '10',  # number of outbound links clicked counting down from 10
  :timestamp => '1294866800'  # current timestamp
}

Notes

Documentation on these cookies is somewhat sparse. Here are the main resources used in putting this library together:

UTMB

Was harder to find documentation on this (thanks to dominikform for the PR). The final link above contains the following details, copied here in case they disappear:

The content of the cookie include domain hash, pageview, number of outbound link click
counting down from 10, and current time stamp

Copyright © 2011 Simon Robson. See LICENSE for details.

ga_cookie_parser's People

Contributors

simonrobson avatar dfguo avatar dominikform avatar cyrus-captap avatar

Watchers

André Branco avatar

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.