Giter Club home page Giter Club logo

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

Python Google Analytics Cookie Parser

Python Google Analytics Cookie Parser is a simple class for parsing useful visitor and referral data from a Google Analytics cookie.

Utilize it during your sign up process in order to permanently store informations about where your customers came from, which opens the door for all sorts of useful metrics...

Cookie Breakdown

From utma to utmz is a decent blog post that explains, at a high level, the various cookies Google Analytics uses to store data. The two most interesting (at least to me) are the utma and utmz cookies:

  • utma is a persistent cookie that tracks the number of visits, and times of the first and last visit
  • utmz keeps track of all the referral information, with useful nuggets like ad campaigns and referring domain or search engine

Usage

Instantiate an object with two keyword arguments containing the strings contained in the two cookies. Here's an example that will work on Pylons:

from path.to.google_analytics_cookie import GoogleAnalyticsCookie
utmz = request.cookies['__utmz'] if 'utmz' in request.cookies else None
utma = request.cookies['__utma'] if 'utma' in request.cookies else None
gac = GoogleAnalyticsCookie(utmz=utmz, utma=utma)

Your object will have utma and utmz attributes that are dictionaries with the following keys:

gac.utma['domain_hash']
gac.utma['random_id']
gac.utma['first_visit_at']
gac.utma['previous_visit_at']
gac.utma['current_visit_at']
gac.utma['session_counter']

gac.utmz['domain_hash']
gac.utmz['timestamp']
gac.utmz['session_counter']
gac.utmz['campaign_number']
gac.utmz['campaign_data']['source']
gac.utmz['campaign_data']['name']
gac.utmz['campaign_data']['medium']
gac.utmz['campaign_data']['term']
gac.utmz['campaign_data']['content']

Happy data mining!

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.