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

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.