Skip to main content

Implement Real-Time Interventions in an Ecommerce App Using Signals

Signals implementation
  • Introduction

  • Set up your Signals connection

  • Define attributes and service with Python

  • Define interventions

  • Test with the demo application

  • Conclusion

Last updated on

Set up your Signals connection

The first step is to set up your Signals connection. Follow the instructions in the Signals connection documentation for your chosen deployment method:

Once your connection is set up, gather the required credentials as described in the connection credentials section.

Set up your Jupyter notebook environment

You can use either Google Colab or a local Jupyter notebook environment for this tutorial.

If you want to skip ahead, you can make use of the following notebook that contains all the Python code you'll need for this tutorial:

  1. Python notebook on Google Colab
  2. Jupyter notebook on GitHub

Using Google Colab

You can use the provided notebook, or create your own. To create a new notebook, open a new notebook at Google Colab.

You'll need to add credentials as Colab secrets. Click the key icon in the left sidebar, and add the required secrets:

  • SP_API_URL: your Signals API URL
  • SP_API_KEY: your API key
  • SP_API_KEY_ID: your API key ID
  • SP_ORG_ID: your Snowplow Console organization ID

When you run the notebook, it will ask for access to the secrets. Choose to grant access.

If you're using your own notebook, follow these steps:

  1. Install the Signals Python SDK:
%pip install snowplow-signals
  1. Load your credentials in the notebook:
from google.colab import userdata
import os

os.environ["SP_API_URL"] = userdata.get('SP_API_URL')
os.environ["SP_API_KEY"] = userdata.get('SP_API_KEY')
os.environ["SP_API_KEY_ID"] = userdata.get('SP_API_KEY_ID')
os.environ["SP_ORG_ID"] = userdata.get('SP_ORG_ID')

Using local Jupyter

Navigate into your working directory and environment, then follow these steps:

  1. Install Jupyter and the Signals SDK:
pip install jupyter snowplow-signals python-dotenv
  1. Create a .env file in your working directory with your credentials:
SP_API_URL=your_signals_api_url
SP_API_KEY=your_api_key
SP_API_KEY_ID=your_api_key_id
SP_ORG_ID=your_organization_id
  1. Start Jupyter notebook:
jupyter notebook
  1. In your notebook, load the environment variables:
from dotenv import load_dotenv
load_dotenv()

Connect to Signals

Now you're ready to connect to your Signals instance using the Python SDK.

from snowplow_signals import Signals
import os

sp_signals = Signals(
api_url=os.environ["SP_API_URL"],
api_key=os.environ["SP_API_KEY"],
api_key_id=os.environ["SP_API_KEY_ID"],
org_id=os.environ["SP_ORG_ID"],
)

You're now ready to start defining attributes and interventions in Signals.

On this page

Want to see a custom demo?

Our technical experts are here to help.