Overview

This library lets you record analytics data from your Python code. Once installed, the requests will be sent to the MetaRouter platform and then sent to the integrations you have configured for your pipeline that is connected to your Python events.

You can use the Python library in your web server controller code. It is built for high performance and uses and internal queue to make all calls non-blocking and fast. It will batch messages and flush asynchronously to the MetaRouter platform.

Install the Library

Install the library using this bash command:

pip install analytics-python

Step 2

Inside your python app, set your pipeline's writeKey inside an instance of the Analytics object.

import analytics
analytics.host = 'YOUR_HOST_URL'
analytics.app_id = ‘YOUR_WRITEKEY’

Required SDK Edits

In the above SDK, you will need to include your custom Host URL. Instructions for setting up your DNS, which includes the Host URL that you will insert into your SDK setup, can be found here. Your writeKey will indicate the specific pipeline you would like to feed your events into.

Event Methods in Python

Check out the below event methods and their use cases to determine the events that you need to trigger. We have also included examples of how you'd call specific objects in Python. More information on event methods can be found here.

Identify

The identify method helps you associate your users and their actions to a unique and recognizable userID and any optional traits that you know about them. We recommend calling an identify a single time - when the user's account is first created and only again when their traits change.

analytics.identify('userID' : '1234qwerty', {
    'name': 'Arthur Dent',
    'email': '[email protected]',
    'friends': 100
})

Track

To get to a more complete event tracking analytics setup, you can add a track call to your website. This will tell MetaRouter which actions you are performing on your site. With track, each user action triggers an event, which can also have associated properties.

analytics.track('userID' : '1234qwerty', 'Signed Up')

Page

The page method allows you to record page views on your website. It also allows you to pass additional information about the pages people are viewing.

analytics.page('user_id', 'Docs', 'Python', {
  'url': 'http://metarouter.io'
})

Group

The group method associates an identified user with a company, organization, project, etc.

analytics.group('user_id', 'group_id', {
  'name': 'MetaRouter',
  'domain': 'Data Engineering Platform'
})