Skip to content

Google Analytics collection api using python - now use it in server as well (not just client)

License

Notifications You must be signed in to change notification settings

zonito/PyAnalytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyAnalytics

Google Analytics collection api - now use it in server as well (not just client). You can track your server side request / API request which are not possible using client js of Google Analytics.

Use Cases

  • Multiplayer games
  • Mobile applications
  • Flash applications / games
  • File download track such as images, pdf, etc

Features

  • PageView
  • Events

Installation

You can install pyanalytics from below methods:

pip

pip install pyanalytics

git

git clone https://github.com/zonito/PyAnalytics.git

Configure below snippet in quack.yaml

modules:
  pyanalytic:
    repository: https://github.com/zonito/PyAnalytics.git
    path: pyanalytics

and then just run

quack

Usages Example

Below are the example on how to use PyAnalytics,

Page View

from PyAnalytics import Config
from PyAnalytics import Tracker

def _get_page(self):
    """Return page object."""
    page = Page('/to/the/tracking/path')
    page.referrer = 'http://google.com/referrer'
    page.load_time = 100
    return page

def _get_session(self):
    """Return session object."""
    session = Session()
    session.session_id = self.post_data.get('user_id')
    return session

def _get_visitor(self):
    """Return visitor object."""
    visitor = Visitor()
    visitor.user_agent = 'Android'
    visitor.locale = 'en'
    visitor.unique_id = int(self.post_data.get('user_id', 0))
    visitor.ip_address = env.get('REMOTE_ADDR', '1.0.0.0')
    return visitor

def track_pageview(self):
    """Track required information per api request."""
    conf = Config()
    tracker = Tracker(self.tracking_code, self.domain, conf=conf)
    tracker.track_pageview(
        self._get_page(),
        self._get_session(),
        self._get_visitor()
    )

Event tracking

def _track_event(self, category=None, action=None, value=0):
    """Global method for sending GA."""
    conf = Config()
    tracker = Tracker(self.tracking_code, self.domain, conf=conf)
    tracker.track_event(
        Event(
            category=category,
            action=action,
            label='something',
            value=value
        ),
        self._get_session(),
        self._get_visitor(),
        self._get_page()
    )

Contributing

We <3 issue submissions, and address your problem as quickly as possible!

If you want to write code:

  • Fork the repository
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'add some feature')
  • Push to your branch (git push origin my-new-feature)
  • Create a new Pull Request

Join Chats

Analytics

About

Google Analytics collection api using python - now use it in server as well (not just client)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages