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
learn and have fun developing 2D retro games using python and pygame

Retro 2D Game Development Using Python + PyGame Skill up your programming skills with a walk down the memory lane. Learn how to create a retro 2D game

Marvin Trilles 1 Feb 23, 2022
A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

Amos 3 Aug 29, 2021
Game Boy emulator written in Python

If you have any questions, or just want to chat, join us on Discord. It is highly recommended to read the report to get a light introduction to Game B

Mads Ynddal 3.7k Dec 30, 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
2D ping pong game

pingpong 2D Ping Pong game How to play: player 1 w To move up s To move Down player 2 up To move up down To move Down To change the game settings, you

menachem 0 Mar 27, 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
A Neural Network based chess engine and GUI made with Python and Tensorflow/Keras.

Haxaw-Chess Haxaw: Haxaw is the Neural Network based chess engine made with Python and Tensorflow/Keras. Also uses the python-chess library. (WIP: Imp

Sarthak Bharadwaj 8 Dec 10, 2022
Tic tac toe game developed by naman in python

TIC TAC TOE GAME DEVELOPED BY NAMAN IN PYTHON . IT USES MINMAX ALGORITHM TO COMPETE IN DIFFICULTY MODE

Naman Anand 4 Jun 24, 2022
A python snake game based on pygame.

PySnake A python snake game based on pygame. Requirements Package version pygame = 2.1.2 opencv-python = 4.5.1.48 Run Windows python main.py Linux &

2 Jan 31, 2022
Made with pygame. Multiplayer game using socket module and threading.

Rock Paper Scissor made with python-pygame. Poorly made, as a beginner in programming. Multiplayer with server code and client code provided.

AllenJo 1 Dec 29, 2021
AI Mario challenges you to clear all stage of Super Mario game.

mario-ai-challenge Challenge AI Mario to clear all stages of Super Mario. GitHub Pages Site Rules Enjoy building AI Mario. Share information. Use Goog

karaage 48 Dec 10, 2022
2d war game single player

WarGame-third-version-0.0.4- 2d war game single player Hi ! Today, I publish on GitHub the version 0.0.4 of "WarGame". In this version, you can find a

Edouard Vincent 2 Apr 08, 2022
An asynchronous Minecraft server wrapper written in python3 with asyncio

mark3 (WIP) A modern Minecraft server wrapper written in python3 with asyncio TODO Note: The order of the following checklist doesn't necessarily mean

Colin Andress 7 Jul 29, 2022
Guess Your Card - A Multiplayer Python Game

Guess Your Card - A Multiplayer Python Game This is a guessing card game having two levels - Developed in Python and can be played between two to four

Hammad Ahmed ~ 1 Oct 20, 2021
Official PyTorch implementation of NAC from the paper: Neural Auto-Curricula in Two-Player Zero-Sum Games.

NAC Official PyTorch implementation of NAC from the paper: Neural Auto-Curricula in Two-Player Zero-Sum Games. We release code for: Gradient based ora

Xidong Feng 19 Nov 11, 2022
This is a classic guess coin game (Heads or Tails) implemented by the Chialisp.

This is a classic guess coin game (Heads or Tails) implemented by the Chialisp. It is an absolutely fair P2P game based on the Chia blockchain. You can play with anyone in the world without custody.

Kronus91 14 Jul 02, 2022
Python module providing simple game networking

nethelper Python module providing simple game networking This module was originally created to facilitate a class on creating multiplayer games in Pyg

Cort 3 Jan 11, 2022
QuizGame is a quiz with different topics. You can choose a topic and take the quiz

QuizGame is a quiz with different topics. You can choose a topic and take the quiz. In the end you will get your result. The program is under active development, so there may be errors or flaws in it

Lev Likhachev 2 Nov 12, 2021
Este repositorio es creado con el fin de brindar soporte a las personas que están en el proceso de aprendizaje MISIONTIC 2022 en la universidad de Antioquia

Este repositorio es creado con el fin de brindar soporte a las personas que están en el proceso de aprendizaje MISIONTIC 2022 en la universidad de Antioquia. Hecho por los estudiantes para los estudi

Andrés Mauricio Gómez 11 Jun 22, 2022
A set of functions compatible with the TIC-80 platform

Pygame-80 A set of functions from TIC-80 tiny computer platform ported to Pygame 2.0.1. Many of them are designed to work with the NumPy library to im

7 Aug 08, 2022