1. Alexey Strelkov
  2. PyGA

Wiki

Clone wiki

PyGA / Home

PyGA - Python Google Analytics server-side tracking

What it is

It's a small module for python server-side google analytics tracking (or, simply, pyGA). It lets you track your page views via server-side.

It's an adaptation of a script from here Also used bit of code from this adaptation

The goal is to make the code cleaner, pythonic and more usable.

Original Google Analytics Reference is here

What it is good for

It's good for mobile web if you don't want to use any js on your pages (like for old phones, for example)

It's extremely useful if your site provides an external API, so you can track your API calls. That's the main reason why this implemention exists.

Usage

Generic

from pyga import GATracker

ga = GATracker('domain.com', 'UA-xxxx')
ga.track('/api/news/', user_session_id, ip_address, useragent)

Flask

Basic

import flask
from flask import request, session #secret_key must be set to use session, see flask docs

from pyga import FlaskGATracker

#<...>

ga = FlaskGATracker('domain.com', 'UA-xxxx')
ga.track(request, session)

Parameters

(ip address and so on keys will be described here)

Django

Basic

#in you views.py

from pyga import DjangoGATracker

def some_view(request):

    ga = FlaskGATracker('domain.com', 'UA-xxxx')
    ga.track(request)

    #<...>

Installation

Via Pip

pip install -e git+https://bitbucket.org/DataGreed/pyga.git#egg=pyga-dev

Updated