Skip to main content

Python SDK for AudienceLab services

Project description

AudienceLab Python SDK

With the introduction of Apple's App Tracking Transparency (ATT) framework, mobile advertisers have faced significant challenges in measuring ad performance on iOS. This challenge is set to expand further with Google's upcoming Privacy Sandbox, reducing visibility into user-level attribution.

Geeklab is dedicated to developing a privacy-first marketing performance analytics platform that enables advertisers to gain actionable insights while adhering to evolving data privacy regulations. Our solution aggregates performance data at the device/developer server level and provides creative-level analytics, ensuring that advertisers can optimize campaigns without relying on user-level tracking.

Overview

The Audiencelab Python SDK is a lightweight client library for integrating with the AudienceLab API. It simplifies:

  • User registration and creative token fetching
  • Sending in-app events (purchases, ad views, retention events)
  • Collecting and managing device and user information
  • Automatic cumulative value tracking for purchase and ad revenue

Installation

pip install audiencelab-python-sdk

Basic Usage

1. Initialize the Client and Construct User Data

First, import the necessary classes from the SDK. Create a client instance using your API key and base URL, and then build the user data object.

Note: Detailed device information is only required during the initial user registration. For all subsequent events, simply provide the user ID and IP address. If the event did not occur in real time, be sure to include the event timestamp (ISO 8601).

from audiencelab_python_sdk import Client, UserData, RegisterUser, FetchToken, RetentionData, PurchaseData, AdData, AppEvent

api_key = "your_api_key"
base_url = "https://example.com"
client = Client(api_key, base_url)

# Initialize UserData
user_data = UserData() \
    .set_user_id("user_12345") \
    .set_user_ip("123.123.1.1") \
    .set_app_version("1.2.3") \
    .set_event_timestamp("2024-10-05T16:48:00+02:00") \
    .set_device_info({
        "device_name": "My Device",
        "height": 2436,
        "width": 1125,
        "os": "iOS",
        "os_version": "14.4",
        "device_model": "iPhone15,4",
        "timezone": "America/New_York"
    })

2.1 Register a User

Register a new user; Call this only once when a new user first downloads and opens the app.

This event will also return creative token information which updates your user data with the creative token information. In this case, step 2.2 is not required.

register_event = RegisterUser(client, user_data)
try:
    response = register_event.send()
    user_data.set_user_creative_token_info(response)
    print("User registered & creative token information set.")
except Exception as e:
    print("Error during user registration:", e)

2.2 Fetch the Creative Token

Creative token information fetching; Call this once before sending any user related in app events.

fetch_event = FetchToken(client, user_data)
try:
    response = fetch_event.send()
    user_data.set_user_creative_token_info(response)
    print("Creative token information set.")
except Exception as e:
    print("Error fetching creative token:", e)

3. Send In-App Events

⚠️ Note:
Make sure to set both the user ID and the user IP address on your user_data (e.g., using .set_user_id() and .set_user_ip()) before fetching the creative token and sending an in-App event! Both are required.

Retention Event

The retention event should be sent each time the user opens the app, including after the initial user registration event.

retention_data = RetentionData().set_retention_data(user_data)
retention_event = AppEvent(client, retention_data, user_data)
try:
    response = retention_event.send()
    print("Retention event sent")
except Exception as e:
    print("Error sending retention event:", e)

Purchase Event

The SDK automatically tracks cumulative purchase values. Each purchase event updates the running total on both the backend and in local state.

purchase_data = PurchaseData() \
    .set_item_id("item_123") \
    .set_item_name("No Ads") \
    .set_value(3.99) \
    .set_currency("usd") \
    .set_status("completed") \
    .set_transaction_id("txn_abc123")  # Optional: unique transaction identifier
purchase_event = AppEvent(client, purchase_data, user_data)
try:
    response = purchase_event.send()
    print("Purchase event sent")
except Exception as e:
    print("Error sending purchase event:", e)

Ad View Event

The SDK automatically tracks cumulative ad revenue values. Each ad event updates the running total on both the backend and in local state.

ad_data = AdData() \
    .set_ad_id("ad_123") \
    .set_name("New Game Ad") \
    .set_source("rewarded_video") \
    .set_media_source("admob") \
    .set_channel("paid") \
    .set_watch_time(4321) \
    .set_reward(True) \
    .set_value(0.00035) \
    .set_currency("usd") \
    .set_transaction_id("ad_txn_xyz789")  # Optional: unique transaction identifier
ad_event = AppEvent(client, ad_data, user_data)
try:
    response = ad_event.send()
    print("Ad view event sent")
except Exception as e:
    print("Error sending ad view event:", e)

License

This project is licensed under the terms of the GEEKLAB SDK EULA.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

audiencelab_python_sdk-1.0.4.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

audiencelab_python_sdk-1.0.4-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file audiencelab_python_sdk-1.0.4.tar.gz.

File metadata

  • Download URL: audiencelab_python_sdk-1.0.4.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for audiencelab_python_sdk-1.0.4.tar.gz
Algorithm Hash digest
SHA256 59f1c0440218aaa9d40f7bc1e12f86b137b09fe891d29c0e1d3cc449c7a26bf8
MD5 df542e9608ffdca7fa951e572c5f0daf
BLAKE2b-256 50585f7bf7fd7fa7fac6a277d5fc0b9f9ef34a091ae0767bd50630535434e1ef

See more details on using hashes here.

File details

Details for the file audiencelab_python_sdk-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for audiencelab_python_sdk-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca78c2206041b10d49ef5442272c25350a56b1e363bb23e7534de7596e30d039
MD5 ffdec0818675727ba57d1b6f0fbc201e
BLAKE2b-256 f9d2226f8dadfd0c29edf67831d57936d73bc3cca872d271ecb3e9dfacb2bb3c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page