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
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
Synthesizer based on Conway's Game of Life

Conway Synth Synthesizer based on Conway's Game of Life Trying to avoid step sequencer fashions that have been done before and basing it on actual cel

Giacomo Loparco 4 Mar 15, 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
A python-based multi-player online educational game for students to play in a class or club setting.

Kurono (codename: aimmo) Code for Life has been developed by Ocado Technology as a free, open-source project to inspire the next generation of compute

Ocado Technology 108 Nov 07, 2022
Pygame for humans (pip install hooman) (25k+ downloads)

hooman ~ pygame for humans pip install hooman join discord: https://discord.gg/Q23ATve The package for clearer, shorter and cleaner PyGame codebases!

Abdur-Rahmaan Janhangeer 31 Nov 08, 2022
Wordle - Implementation of wordle and a solver

Wordle - Implementation of wordle and a solver

Kurt Neufeld 1 Feb 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
An interactive pygame implementation of Conway's Game of Life

Game of Life An interactive pygame implementation of Conway's Game of Life Installation Clone the repo and navigate into it. git clone https://github.

Ethan 1 Dec 05, 2021
Jogo da velha com interface gráfica desenvolvida em Python utilizando pygame e IA(Inteligência Artificial)

Jogo-da-Velha Sobre o projeto Jogo da velha com interface gráfica desenvolvida em Python utilizando pygame e IA(Inteligência Artificial) Layout tela d

Matheus Maia Alvarez 6 Apr 09, 2022
Dota2 AI bot - Last Order Dota2 Solo AI

Last Order Dota2 Solo AI 该库提供一个由强化学习训练出的Dota2影魔solo智能体。该智能体通过自我对战的训练方式训练,从随机动作开始学习复杂的策略。玩家可以与该智能体进行影魔solo对战。 对战规则 1.物品方面不可以出凝魂之露,灵魂之戒,魔瓶,真眼。 2.不可以吃符,或

bilibili 365 Jan 05, 2023
Web frontend to play games from 2008 Miniclip - uses Ruffle for playback

cliparchive Description A set of scripts to download games from the Wayback Machine's archive of Miniclip.com, and a Web frontend to play them using r

Simon Garrelou 3 Dec 09, 2022
Fully functional BlackJack game with a graphical user interface.

BlackJack Welcome to BlackJack! This game is fully functional, with a casino sound package integrated using Pygame, dynamic game logic developed using

Shwetang Desai 2 Jan 10, 2022
Flappy Bird Game using Pygame in Python

Flappy Bird Game using Pygame in Python Demo Pages Hello dear, hope you are very well! I created Flappy Bird Game using Pygame ( Pygame is a cross-pla

Datt Panchal 3 Feb 05, 2022
Tic-Tac-Toe Game in python3 Tkinter

Tic Tac Toe Tic-Tac-Toe Game in python3 Tkinter About: Tic Tac Toe or Noughts and Crosses as called in British is a pencil and paper game for two play

Sai Swarup Yakkala 5 Nov 06, 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
A visualization of how much Manchester United fans enjoyed each game from the first half of the 21/22 Premier League season.

Man-Utd-Fan-Satisfaction-Levels-First-19-games A visualization of how much Manchester United fans enjoyed each game from the first half of the 21/22 P

1 Jan 19, 2022
Snake Game in Python

Snake game is one of the most popular arcade games of all time. In this game, the main objective of the player is to catch the maximum number of fruits without hitting the wall or itself.

Pavan Ananth Sharma 4 Jul 05, 2022
Among Us Editor written in Python, for newer versions of the game

Among Us Editor Remake Among Us Editor written in Python, for newer versions of the game. Credits GUI Code by Vresod Data dumping and some GUI code by

Vresod 7 Nov 18, 2022
A simple pygame implementation of the LOGO programming language.

LOGO-py A simple pygame implementation of the LOGO programming language. Latest Version Notes Fixed a bug where penup/pendown would not work properly.

Ethan Evans 1 Dec 05, 2021
A Game of Life implementation in Python

Game of Life in Python (Golipy) Golipy is a simulator of John H. Conway's Game of Life, developed in Python based on the Pygame library. This is a toy

Alber 2 Dec 10, 2021