Skip to main content

Django app for extracting and storing UTM tracking values.

Project description

Django UTM Tracker

Django app for extracting and storing UTM tracking values.

Background

This app has been designed to integrate the standard utm_* querystring parameters that are used by online advertisers with your Django project.

It does not replace analytics (e.g. Google Analytics) and Adwords tracking, but does have one crucial difference - it allows you to assign a specific user to a campaign advert.

This may be useful if you are trying to assess the value of multiple channels / campaigns.

How it works

The app works as a pair of middleware classes, that extract utm_ values from any incoming request querystring, and then store those parameters against the request.user (if authenticated), or in the request.session (if not).

The following shows this workflow (pseudocode - see test_utm_and_lead_source for a real example):

client = Client()
# first request stashes values, but does not create a LeadSource as user is anonymous
client.get("/?utm_medium=medium&utm_source=source...")
assert utm_values_in_session
assert LeadSource.objects.count() == 0

# subsequent request, with authenticated user, extracts values and stores LeadSource
user = User.objects.create(username="fred")
client.force_login(user, backend=settings.FORCED_AUTH_BACKEND)
client.get("/")
assert not utm_values_in_session
assert LeadSource.objects.count() == 1

Why split the middleware in two?

By splitting the middleware into two classes, we enable the use case where we can track leads without utm_ querystring parameters. For instance, if you have an internal referral program, using a simple token, you can capture this as a LeadSource by adding sentinel values to the request.session:

def referral(request, token):
    # do token handling
    ...
    # medium and source are mandatory for lead source capture
    request.session["utm_medium"] = "referral"
    request.session["utm_source"] = "internal"
    # campaign, term and content are optional fields
    request.session["utm_campaign"] = "july"
    request.session["utm_term"] = token
    request.session["utm_content"] = "buy-me"
    return render(request, "landing_page.html")

Configuration

Add the app to INSTALLED_APPS, and add both middleware classes to MIDDLEWARE.

The UtmSession middleware must come before LeadSource middleware.

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

django-utm-tracker-0.5.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

django_utm_tracker-0.5-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file django-utm-tracker-0.5.tar.gz.

File metadata

  • Download URL: django-utm-tracker-0.5.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.1 Darwin/20.1.0

File hashes

Hashes for django-utm-tracker-0.5.tar.gz
Algorithm Hash digest
SHA256 f3a907b3073fd4c5928942d0a1e129642e3aa65101b6f3e780f10101f90139f7
MD5 eb0b3821f6b27d5f1caaf6c806cdf0f2
BLAKE2b-256 b4d5f1af36559627f2df102a4b3222436727a5acc87fad98a33421d9b6be986c

See more details on using hashes here.

File details

Details for the file django_utm_tracker-0.5-py3-none-any.whl.

File metadata

  • Download URL: django_utm_tracker-0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.1 Darwin/20.1.0

File hashes

Hashes for django_utm_tracker-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 65f0285810476022a32815afa719ac4ae9ef9937c3d2445c52ec8c61f5fcba90
MD5 b02e442d055bca546fa77340b03d153b
BLAKE2b-256 e5887eb77bfd9bad6ca769e5ccf5dc601078cc9a7af7c3b5a380052897687c5c

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