Tealium for Python

Tealium for Python

by on ‎04-15-2016 11:12 AM - edited 2 weeks ago by Community Manager (452 Views)

This guide shows how to add Tealium to your Python application to track activity in the Universal Data Hub.

Table of Contents Placeholder

Getting Started

Requirements

Install 

The Tealium for Python package can be installed using pip. If you haven't used pip before please read the pip installation guide.

Using Python 2:

pip install tealium

Using Python 3:

pip3 install tealium

Initialization

Once the Tealium for Python package is installed you are ready to start coding. Use the following code to import the Tealium module and initialize with the following parameters:

  • account - the name of your account
  • profile - the name of the profile within your account
  • environment - one of "qa", or "prod" 
from tealium import Tealium
teal = Tealium('account', 'profile', 'environment')

Tracking

Once the Tealium object has been defined you can begin tracking events with the method trackEvent(), which takes the following parameters:

  • Event Name (required) - a name to identify the event
  • data - optional dictionary with event data as key/value pairs
  • eventtype - optional Tealium event type (default is Tealium.EVENT_TYPE_ACTIVITY
  • callback - optional callback function

In any function that triggers or responds to an event trigger 

def tealiumCallback(info, success, error=None):
if error is not None:
print (info, success, error)
return
print (info, success)

eventData = {'someKey': 'someValue'}
teal.trackEvent('someEvent',
data:eventData,
eventtype:Tealium.EVENT_TYPE_VIEW,
callback:tealiumCallback) 

Additional Resources

Function Definitions

Tealium()

Creates a Tealium object that will be used to track events.

teal = Tealium(account, profile, environment)
Parameters Type Description
account String Tealium account name eg. "companyXYZ"
profile String Tealium profile name eg. "main"
environment String Tealium environment identifer eg. "prod"

trackEvent()

Creates a Tealium object that will be used to track events.

teal.trackEvent(eventName, data:eventData, eventtype:eventtype, callback:callback)
Parameters Type Description
eventName String Name of the event eg. "user_login"
data Dictionary Dictionary of additional data source keys and values (optional)
eventtype Tealium Type Optional Tealium tracking type: EVENT_TYPE_ACTIVITY (default), EVENT_TYPE_VIEW, EVENT_TYPE_CONVERSION, EVENT_TYPE_DERIVED, EVENT_TYPE_INTERACTION
callback Function Optional callback function

resetSessionId()

Reset the session ID. For use when needing to start a new session other than at app start time.

teal.resetSessionId()
Returns Description Example Value
String A timestamp in milliseconds, converted to a String, that is associated with all subsequent tracking. The session ID is maintained internally and automatically included as the tealium_vid event attribute. "1473371215123"
teal.resetSessionId()