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
Blackjack-Py is a terminal based game of blackjack within your terminal playing against CPU.

About Blackjack-Py is a terminal based game of blackjack within your terminal playing against CPU. Usage Clone the repo and run it with whatever pytho

Eccentrici 1 Dec 28, 2021
An implementation of John Conway's Game of Life.

This is an implementation of John Conway's Game of Life in Python, and a very basic and straightforward one at that.

Mae 3 Feb 11, 2022
This is a simple game of rock-paper-scissors developed in Python

This is a simple game of rock-paper-scissors developed in Python. It allows two players to play with one another on different command lines through networking.

NAMAN JAIN 3 Oct 21, 2022
Unknown Horizons official code repository

Unknown-Horizons based on Fifengine is no longer in development. We are porting it to Godot Engine. Please dont report any new bugs. Only bugfixes wil

Unknown Horizons 1.3k Dec 30, 2022
Guess number game with PyQt5

Guess-Number-Project Guess number game with PyQt5 you can choose a number in your mind and then computer will guess a nummber and you guide the comput

MohammadAli.HBA 1 Nov 11, 2021
Simple program to play Metamon automatically

Getting Started Radio Caca Important disclaimer This software is intended for use by individuals familiar with Python programming language. It uses se

Metamon Island 35 Dec 28, 2022
A Higher-Lower web game made in Python using Flask framework.

Higher Lower Web Game Guess the random number from 0 to 9 in this web game made with Python and Flask Framework Modules that were used Random Flask In

Yago Goltara 1 Oct 27, 2021
PyUnity is a Python implementation of the Unity Engine, written in C++

PyUnity is a Python implementation of the Unity Engine, written in C++. This is just a fun project and many features have been taken out to make it as easy as possible to create a scene and run it.

PyUnity 206 Jan 03, 2023
This is a good project to train your logic game with python language

JO-KEN-PÔ!!! | Description | basic. I make this game only to train. This is a good project to train your logic game with python language. This game is

Elianderson Silva 1 Jan 24, 2022
An old time game Tic-Tac-toe

A Tic Tac Toe Bot This is the code repository for my article on Medium - Playing Games with Python - Tic Tac Toe, where I have tried to take the famou

Jigyanshu 0 Feb 25, 2022
Vac-Man in Python

Vac-Man in Python This is my personal version of Vax-man game using python, which is the first task of EA Software Engineering Virtual Experience Prog

ZiXiang Luo 3 Jan 05, 2022
Battle of Saiyans: Goku v Vegeta is a 1 v 1, (Player vs CPU) 2D Martial arts fighting game

Battle of Saiyans: Goku v Vegeta is a 1 v 1, (Player vs CPU) 2D Martial arts fighting game inspired by the popular anime series Dragon Ball Z The game

ARZ 3 Feb 16, 2022
Given some input, spit out the possible words for a Wordle puzzle

Wordle Helper, because why not. Given some input, spit out the possible words for a Wordle puzzle First time setup # Download the dictionary to a file

Richard Duarte 1 Jan 25, 2022
The main objective of the game is to destroy multiple waves of asteroids with the help of a blaster mounted on the spaceship.

Astronomia: let the exploration begin The main objective of the game is to destroy multiple waves of asteroids with the help of a blaster mounted on t

Aryan Nath 8 Nov 18, 2022
Attempts to solve Wordle-like puzzles.

Attempts to solve Wordle-like puzzles.

cotman 1 Feb 14, 2022
View your VALORANT performance in different areas of every map in the game!

Valorant-Zone-Stats Inspired by Leetify's awesome Map Zones Tool for CS:GO A simple desktop program to view your VALORANT performance in different are

Louis 76 Jan 01, 2023
An single python server emulator of MMORPG game WindSlayer also known as WS1.

PySlayer An single python server emulator of MMORPG game WindSlayer also known as WS1. Requirements Python = 3.7 Old windslayer client (Korea Yahoo!

mirusu400 29 Dec 19, 2022
Python game engine for 2D multiplayer online games.

LAN-Caster The goal of LAN-Caster is to provide an easy-to-use code base (game engine) for developing 2D multiplayer online games. LAN-Caster original

Douglas Bakewell 1 Feb 11, 2022
Pyout - A little Krakout clone called Pyout written in Python 3

Pyout My little Krakout clone called Pyout written in Python 3

Jan Karger ツ ☀ 4 Feb 20, 2022
SuperChess is a GUI application for playing chess.

About SuperChess is a GUI application for playing chess. It is written in Python 3.10 programming language, uses PySide6 GUI library, python-chess lib

Boštjan Mejak 1 Oct 16, 2022