PYGA: Python Google Analytics (ga.js) - Data Collection API

Overview

PYGA: Python Google Analytics - Data Collection API

Build Status https://coveralls.io/repos/github/kra3/py-ga-mob/badge.svg?branch=master

pyga is an implementation of Google Analytics (ga.js) in Python; so that it can be used at server side. This project only helps you with Data Collection part of Google Analytics. ie., You can consider this as a replacement for ga.js at client side.

Google Provides Android SDK,iOS SDK + Flash SDK. And left everybody else with a single page documentation about GIF request parameters. Also with a basic sample of server side implementation in quite a few languages (perl, php, jsp).

PS: Google moved away from ga.js to analytics.js; a new operating standard for Google Analytics named "universal analytics". Soon ga.js will be deprecated. I'm planning to have a pyga equivalent to the new standard. Read more here at https://developers.google.com/analytics/devguides/collection/upgrade/#upgrade-guides https://developers.google.com/analytics/devguides/collection/protocol/v1/#getting-started

Use Cases

  1. You want to track data from server side
  2. You're developing a mobile site and have to support devices w/o JS support

Supported Features

  • Page View

  • E-Commerce

  • Social Interaction

  • Custom Variables

  • Events

  • Campaigns

    not yet

  • Ad-Words

  • Search Engine

To know more about mobile-tracking see: https://developers.google.com/analytics/devguides/collection/other/mobileWebsites

Example

from pyga.requests import Tracker, Page, Session, Visitor

tracker = Tracker('MO-XXXXX-X', 'yourdomain.com')
visitor = Visitor()
visitor.ip_address = '194.54.176.12'
session = Session()
page = Page('/path')
tracker.track_pageview(page, session, visitor)

PHP version

Thanks to: Expicient Inc

And for you fans out there, we even have mountain bikes named pyga ;)

Comments
  • pyga sending location of my server to GA instead of browser location

    pyga sending location of my server to GA instead of browser location

    Hey, Not sure why this happens to me, Any ideas? thanks

    One important point is that the visits to the views which generate those events are from a chrome extension (no an actual page view), so maybe something is missing from the user's request.

    Here's my code (removed personal data):

    def reportGA(category,action,label,request):
        try:
            x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
            if x_forwarded_for:
                ip = x_forwarded_for.split(',')[0]
            else:
                ip = request.META.get('REMOTE_ADDR')
            print ip
            from pyga.requests import Tracker, Page, Event, Session, Visitor
            tracker = Tracker('UA-********-1', '******.com')
            visitor = Visitor()
            visitor.ip_address = '' #ip
            session = Session()
            event = Event(category,action,label)
            tracker.track_event(event, session, visitor)
        except:
            print "failed to report to GA"
    
    opened by medaveanderson 10
  • unique_id in Visitor should not be lazy

    unique_id in Visitor should not be lazy

    Actually unique_id in Visitor is lazy and that will be a problem if you try to serialize it before unique_id is used, for example if

    try:
        visitor = loads(user.googleanalytics.serialized_user.encode('ascii'))
    except GoogleAnalytics.DoesNotExist:
        visitor = Visitor()
        visitor.ip_address = '8.8.8.8'
        GoogleAnalytics.objects.create(user=user, serialized_user=dumps(visitor))
    
    tracker = Tracker('UA-12-13', 'domain.com')
    
    page = Page(request_data.get('page', ''))
    
    tracker.track_pageview(page, Session(), visitor)
    

    As it is serialized and saved in database before tracker.track_pageview, unique_id was never acessed so it will be None and if you deserialize it and access unique_id, it will not be the same. I think, it could be like this https://github.com/jaysonsantos/py-ga-mob/commit/861f149b81f7955629419b657afd0ee575266857

    opened by jaysonsantos 7
  • UnicodeEncodeError in function  __escape_extensible_value

    UnicodeEncodeError in function __escape_extensible_value

    To reproduce the bug, use a unicode string event = GAEvent(category='category', action='action', label=u'éàè') tracker.track_event(event, session, visitor)

    Maybe we should replace ''.join(map(_translate, str(value))) by u''.join(map(_translate, value)).encode('utf-8')?

    Maybe some explanations here: http://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20

    opened by benoitguigal 5
  • Events don't seem to work

    Events don't seem to work

    Unless I'm missing something, I don't believe that event tracking works properly.

    In particular, I perform the following sequence of operations:

    
    from pyga.requests import Tracker, Session, Visitor, Event
    tracker = Tracker('MO-XXXXX-X', 'yourdomain.com')
    visitor = Visitor()
    visitor.ip_address = '194.54.176.12'
    session = Session()
    event = requests.Event(category, action, label)
    tracker.track_event(event, session, visitor)
    

    Yet when I check Google analytics the next day, none of the events that I explicitly executed make it to Google analytics.

    Is there some other step that I'm missing?

    bug 
    opened by josiahcarlson 4
  • Python 3 support based on the defunct fork by @LukGerman

    Python 3 support based on the defunct fork by @LukGerman

    Remove dependency on six, and made python3 compatible.

    Probably worth doing a major release with only python 3 support, this library may get a bit more attention with new browser tracking script blocking that's happening in firefox and safari.

    opened by olymk2 3
  • Please consider adding support for Batch requests.

    Please consider adding support for Batch requests.

    opened by bilalba 3
  • tracker.track_pageview ; sequence item 0: expected a bytes-like object, NoneType found

    tracker.track_pageview ; sequence item 0: expected a bytes-like object, NoneType found

    Hi, I am looking forward to track the visit on an url of my django website. Url that doesn't have a page, and will have a different behaviour depending if you are on mobile or desktop.

    The thing is, as I just want to know the traffic on it, I copied pasted your example (that seems to be enough for what I want) from your doc: tracker = Tracker('UA-XXXXX-XX', 'mydomain.com') visitor = Visitor() visitor.ip_address = '194.54.176.12' session = Session() page = Page('/en/directdownload') tracker.track_pageview(page, session, visitor)

    but then, when I go to the url I have this error:

    sequence item 0: expected a bytes-like object, NoneType found Request Method: GET Request URL: http://192.168.33.15:8000/en/directdownload/ Django Version: 1.7.10 Exception Type: TypeError Exception Value:
    sequence item 0: expected a bytes-like object, NoneType found Exception Location: /usr/lib/python3.4/http/client.py in putheader, line 1067

    Do you have any idea about it?

    opened by Vesli 3
  • Remove the namespace declaration

    Remove the namespace declaration

    After installing the package via pip, the init.py from the source distribution does not exist. It is instead replaced by:

    pyga-2.4.2-py2.7-nspkg.pth

    Which does some magic to make sure that sys.modules is updated correctly

    I am installing pyga and deploying it to appspot and the import fails because init.py is missing.

    opened by nickjoyce-wf 3
  • Fix failing installation when six isn't installed

    Fix failing installation when six isn't installed

    In setup.py, the version and license information would get imported from pyga.requests - a module that imports six. Therefore installation never works when six is not yet installed, even though it's listed as a requirement.

    opened by jochem 2
  • Extra get args withing the language data?

    Extra get args withing the language data?

    Thanks for the awesome library.

    I started including the anonimize ip and the user agent as a holder for the Operating system... but now the data in the language section is getting all these extra params.

    image

    Any thought on this?

    opened by goanpeca 2
  • pip grabbing wrong file from pypi

    pip grabbing wrong file from pypi

    Doing a pip install -U -r on our requirements file which list "pyga", results in the following error after the release of pyga 2.5.0. The issue appears to be that pip is trying to install from the pyga-2.5.0.linux-x86_64.tar.gz file instead of pyga-2.5.0.tar.gz

    Downloading/unpacking pyga from https://pypi.python.org/packages/any/p/pyga/pyga-2.5.0.linux-x86_64.tar.gz#md5=1426b2f4cc326a85877d7682ee292fd7 (from -r requirements_dev.txt (line 17)) build 30-Aug-2013 20:11:14 Downloading pyga-2.5.0.linux-x86_64.tar.gz build 30-Aug-2013 20:11:14 Running setup.py egg_info for package pyga build 30-Aug-2013 20:11:14 Traceback (most recent call last): build 30-Aug-2013 20:11:14 File "", line 16, in build 30-Aug-2013 20:11:14 IOError: [Errno 2] No such file or directory: '/tmp/venv/build/pyga/setup.py' build 30-Aug-2013 20:11:14 Complete output from command python setup.py egg_info: build 30-Aug-2013 20:11:14 Traceback (most recent call last): build 30-Aug-2013 20:11:14
    build 30-Aug-2013 20:11:14 File "", line 16, in build 30-Aug-2013 20:11:14
    build 30-Aug-2013 20:11:14 IOError: [Errno 2] No such file or directory: '/tmp/venv/build/pyga/setup.py' build 30-Aug-2013 20:11:14
    build 30-Aug-2013 20:11:14 ---------------------------------------- build 30-Aug-2013 20:11:14 Command python setup.py egg_info failed with error code 1 in /tmp/venv/build/pyga

    opened by ryanbonham-wf 2
  • Python3.7: TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str. when I have query_string > 2036

    Python3.7: TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str. when I have query_string > 2036

    Describe the bug I can see this error if I have: query_string > 2036. As I can see the problem in pyga.requsts.py in build_http_request link to method

    So, as you can see when query_string > 2036 we try to use post and set query_string as a data post = query_string. Than it raise this error.

    Error stack-trace:

    File "pyga/requests.py", line 880, in track_event
              request.fire()
      File "pyga/requests.py", line 110, in fire
                  self.__send()
      File "pyga/requests.py", line 96, in __send
                      request, timeout=self.config.request_timeout)
      File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
          return opener.open(url, data, timeout)
      File "/usr/local/lib/python3.7/urllib/request.py", line 523, in open
                  req = meth(req)
      File "/usr/local/lib/python3.7/urllib/request.py", line 1280, in do_request_
                      raise TypeError(msg)
    TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
    

    To Reproduce Steps to reproduce the behavior:

    1. Use Python3.7
    2. Build http request where query_string > 2036 and use this library
    3. See error

    Expected behavior It should not give an error.

    opened by yurabysaha 0
Releases(v2.6.2)
Owner
Arun Karunagath
I code & architect software systems | Linux <3 | Motorbike <3 | Nature <3
Arun Karunagath
HTTP API for FGO game data. Transform the raw game data into something a bit more manageable.

FGO game data API HTTP API for FGO game data. Transform the raw game data into something a bit more manageable. View the API documentation here: https

Atlas Academy 51 Dec 26, 2022
A comprehensive, feature-rich, open source, and portable, collection of Solitaire games.

PySol Fan Club edition This is an open source and portable (Windows, Linux and Mac OS X) collection of Card Solitaire/Patience games written in Python

Shlomi Fish 368 Dec 28, 2022
Racers-API - a game where you have to go around racing with your car, earning money

Racers-API About Racers API is a game where you have to go around racing with yo

null 3 Jan 9, 2022
Lint game data metafiles against GTA5.xsd for Rockstar's game engine (RAGE)

rage-lint Lint RAGE (only GTA5 at the moment) meta/XML files for validity based off of the GTA5.xsd generated from game code. This script accepts a se

GoatGeek 11 Sep 18, 2022
A hangman game that I created. Thanks to Data Flair for giving me the code!

Hangman A hangman game that I created. Thanks to Data Flair for giving me the code! Run python3 hangman.py in a terminal if you have Python 3. Please

SmashedFrenzy16 0 Dec 24, 2022
Automatic game data translator for RPGMaker-MV

RPGMaker-MV Translator ??️ ?? Use AI to translate all the dialogs and texts of your RPGMaker automatically. ?? You worked hard to make your game, now

Davide Liu 11 Dec 26, 2022
Create a Hangman Game using Python and all techniques of Python.

Hangman Game Created by Fernando Callasaca Game rules: Choose a word and if you guess it will appear completed. In case it is not the word then the ma

Fernando Callasaca 3 Nov 1, 2021
pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame 5.6k Jan 1, 2023
A Pygame Hangman Game coded in Python 3. Run Hangman.py in a terminal if you have Python 3

Hangman A Pygame Hangman Game coded in Python 3. Run python3 Hangman.py in a terminal if you have Python 3.

null 1 Dec 24, 2022
This is a python interactive story game that I made to show off what I've learnt in python coding for a month

Purpose The files in this repository are for that of a story game created with python version 3.8.5 The purpose of this project was to get familiar wi

null 0 Dec 30, 2021
Simple Game created using Python & PyGame, as my Beginner Python Project!

Space Invaders This is a simple SPACE INVADER game create using PYGAME whihc have sound and lot's of keyboard functions. Prerequisites More Experience

Gaurav Pandey 2 Jan 8, 2022
Wordle-Python - A simple low-key clone of the popular game WORDLE made with python and a 2D Graphics module Pygame

Wordle-Python A simple low-key clone of the popular game WORDLE made with python

Showmick Kar 7 Feb 10, 2022
Tekken-python-ml - A project of playing tekken game using python

Tekken Python Description Hi this is new project of playing tekken game using py

Programminghut 13 Dec 30, 2022
Minecraft clone using Python Ursina game engine!

Minecraft clone using Python Ursina game engine!

Taehee Lee 35 Jan 3, 2023
Lutris desktop client in Python / PyGObject

Lutris Lutris is an open source gaming platform that makes gaming on Linux easier by managing, installing and providing optimal settings for games. Lu

Lutris 6.1k Dec 30, 2022
Python fitting assistant, cross-platform fitting tool for EVE Online

pyfa What is it? Pyfa, short for python fitting assistant, allows you to create, experiment with, and save ship fittings without being in game. Open s

null 1.4k Dec 22, 2022
AI that plays Flappy Bird Game using the python module NEAT.

Flappy Bird AI [NEAT] AI that plays Flappy Bird Game using the python module NEAT. Instructions Install Python Modules: pip3 install -r requirements.t

Abhisht 5 Jan 26, 2022
Mandaw 2 Mar 1, 2022
Creates a landscape with more accurate river generation in Minecraft version 1.12 using python.

MinecraftLandRiverGen View the following youtube video to set up a world that can interact with the python programs

null 23 Dec 25, 2022