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
Pyxel is a retro game engine for Python.

Pyxel is open source and free to use. Let's start making a retro game with Pyxel!

Takashi Kitao 11.2k Jan 09, 2023
A base chess engine that makes moves on an instance of board.

A base chess engine that makes moves on an instance of board.

0 Feb 11, 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
Racing Fire - A simple game made with pygame.

Racing Fire A simple game in the making. Using pygame, this game is made to feel like an old arcade game. I developed a simple controller for it with

Builder212 1 Nov 09, 2021
Wordle Tas Tool is a terminal application for solving Wordle puzzles

Wordle Tas Tool Terminal application for solving Wordle puzzles Wordle Tas Tool (WTT) is a Python script that iterates over SCOWL95 to solve Wordle pu

1 Feb 08, 2022
Attempts to solve Wordle-like puzzles.

Attempts to solve Wordle-like puzzles.

cotman 1 Feb 14, 2022
XPlaneROS is a ROS wrapper for the XPlane-11 flight simulator.

XPlaneROS XPlaneROS is a ROS wrapper for the XPlane-11 flight simulator. The wrapper provides functionality for extracting aircraft data from the simu

AirLab Stacks 26 Dec 04, 2022
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
Flappy Bird hack using Deep Reinforcement Learning (Deep Q-learning).

Using Deep Q-Network to Learn How To Play Flappy Bird 7 mins version: DQN for flappy bird Overview This project follows the description of the Deep Q

Yen-Chen Lin 6.4k Dec 30, 2022
TicTacToc - Simple TicTacToc game played by minimax algorithm

TicTacToc simple TicTacToc game played by minimax algorithm. This app is based o

5 Apr 05, 2022
Setup minecraft server (Tuinity) to your directory

hapeshiva server-setup Setup minecraft server (Tuinity) for you. Support for optimization Create optimized yml Customazible server port and view dista

3 May 11, 2022
TetrisAI - Tetris AI Bot using computer vision to play game automatically

Tetris AI Tetris AI Bot using computer vision to play game automatically bot.py

11 Aug 29, 2022
A didactic GUI chess game made in Python3 using pygame.

Chess A didactic GUI chess game made in Python3 using pygame. At the moment, there is no AI. The only way you can test the game is by playing against

Leonardo Delfino 1 Dec 22, 2021
MCRPC (Minecraft Resource Pack Comparator) checks your resource pack against any version of Minecraft to show resources missing from your pack for that version.

Minecraft Resource Pack Comparator MCRPC checks your resource pack against any version of Minecraft to show resources missing from your pack for that

3 Nov 03, 2022
Découvrez CubeCraft Launcher, une application uniquement codé en Python et en Batch

Découvrez CubeCraft Launcher, une application uniquement codé en Python et en Batch. Grâce à son interface graphique facile et intuitive, vous pouvez vous retrouver facilement.

1 May 21, 2022
Memory game in Python

Concentration - Memory Game Concentration is a memory game written in Python, inspired by memory-game. Description As stated in the introduction of th

Marco Colonna 0 Jul 21, 2022
A python3 project for generating WorldEdit shematics for the MineClone2 game for Minetest from images.

MineClone2 MapArt This is a python3 project you can use with the MineClone2 game for Minetest. This project take an image and output a WorldEdit shema

3 Jan 06, 2023
Brawl Stars private server for version 30.242

Brawl Stars v30 Brawl Stars v30.242 server emulator written in Python. Requirements: Python 3.7 or higher pymongo dnspython colorama Running the serve

15 Oct 17, 2021
Quantum version of the classical Nim game. An automatic opponent allows to game to not be as easy as it seems.

Nim game Running the game To run the program just launch : python3 game.py Rules This game is inspiring from the Nim game. You are 2 players face to f

Michaël 1 Jan 08, 2022
Arcade-like space shooter game written entirely in python

E.T.-Attack Arcade-like space shooter game written entirely in python Project description A space shooter game - inspired by the legendary game Space

Sven Eschlbeck 2 Dec 17, 2022