Events from Python

See the Overview for details about setting up the Datacoral Collect Events Slice and setting up keys.

Step 1: Install the Python instrumentation module

pip3 install git+ssh://datacoral@vault.phacility.com/diffusion/PYEVT/python-instrumentation.git

Step 2: Sample Python Tracking

Substitute the appropriate environment parameters based on the following definitions.

URL_ENDPOINT : The URL of your Datacoral Events API gateway. Ex. events.dccustomer.datacoral.io

API_KEY : The Datacoral API key to authorize the events invocations. Ex. 1js9q5Gqmk2VDv2omx2WI3yUGV0K7b464fWUJXDX

ENVIRONMENT : Set the environment as dev or prod, based on the emitter of the events

NAMESPACE : The name of this Tracker instance to include with events sent to the collector. The namespace argument attached to every event fired by the new tracker. This allows you to later identify which tracker fired which event if you have multiple trackers running. Ex. landing_pages

APP_ID : Name of application to include with events sent to the collector. The application ID is used to distinguish different applications that are being tracked by the same Snowplow stack. Ex. "finance" or "hr"

Test Python File :

from snowplow_tracker import SelfDescribingJson, Tracker, Emitter
# Initialize the tracker
tracker = Tracker(
Emitter(
'URL_ENDPOINT',
buffer_size=1
),
datacoral_env='ENVIRONMENT',
api_key=['API_KEY'],
namespace="NAMESPACE",
app_id="APP_ID",
encode_base64=True
)
# Send a custom event with your own schema and contexts
tracker.track_unstruct_event(
event_json = SelfDescribingJson(
schema = 'event-json-schema',
data = {
'event_name': 'api',
'action': 'testing-tracking'
}
),
context = [
SelfDescribingJson(
schema = 'custom-context-schema',
data = {
'context_name': 'custom',
'attr1': 'hello',
'attr2': 'world'
}
),
SelfDescribingJson(
schema = 'experiment-context-schema',
data = {
'context_name': 'experiment',
'expName': 'name',
'expValue': 'val'
}
)
]
)