Django SDK

Track customers directly in the Django Web Framework using Woopra’s Django SDK

Download the SDK

Download Django SDK from GitHub

Django SDK Documentation

This SDK allows our users who have servers running the Django Framework to track their visitors via Python code. Tracking directly in Python allows both front-end and back-end visitor tracking:

Note: All Events and properties should be lowercase
  • Front-end: after configuring the tracker, identifying the user, and tracking events in Python, the SDK will generate the corresponding JavaScript code. By passing this code to your view using a hook (example below), you will be able to print that code in your view’s header.
  • Back-end: after configuring the tracker and identifying the user, add the optional parameter: true to the methods track or push. The Python tracker will send the data to Woopra by making HTTP Requests. In this case, the client is never involved in the tracking process.

The first step is to setup the tracker SDK in your file. For example, if you want to set up tracking with Woopra on your homepage, the file should look like:

# import the SDK
import woopra_tracker

def homepage(request):
   woopra = woopra_tracker.WoopraTracker(request)
   woopra.config({'domain' : ''})

   # Your code here...

You can also customize any of Woopra’s properties during this step by adding them to the config_dict.

For example, to update your idle timeout (default: 30 seconds):

# instead of:
woopra.config({'domain' : ''})
# directly write:
woopra.config({'domain' : '', 'idle_timeout' : 15000})

To add custom visitor properties, use the identify(user_dict) function:

woopra.identify({'email' : '', 'name' : 'John Doe', 'company' : 'My Business'})

To identify a user without tracking, you can push() the update to Woopra:

# or, to push through back-end:

To track page views, simply call track():

# For back-end tracking:
woopra.track(back_end_tracking = True)

You can also track custom events through front-end or back-end tracking. Combining previous steps, your file should look like:

import woopra_tracker

def homepage(request):
   woopra = woopra_tracker.WoopraTracker(request)
   # Track a custom event through the front end...
   woopra.track("play", {'artist' : 'Dave Brubeck', 'song' : 'Take Five', 'genre' : 'Jazz'})
   # ... and through the back end by passing the optional param True
   woopra.track('signup', {'company' : 'My Business', 'username' : 'johndoe', 'plan' : 'Gold'}, True)

   # Your code here...
   # When you're done setting up your WoopraTracker object, send a hook containing the value of
   # woopra.js_code() among all the other hooks you are passing to the template.
   response = render(request, 'homepage.html', {'woopra_code': woopra.js_code(), 'foo' : 'bar', })
   return response

add the hook in your template’s header (here homepage.html)

<!DOCTYPE html>
      <!-- Your header here... -->
      <!-- Make sure to deactivate html auto-escaping -->
      {% autoescape off %}{{ woopra_code }}{% endautoescape %}
      <!-- Your body here... -->


Finally, if you wish to track your users only through back-end tracking, you should set the cookie on your user’s browser. If you are planning to do front-end tracking in addition, you can skip this step as the JavaScript tracker will handle it for you.

response = render(request, 'homepage.html', {'woopra_code': woopra.js_code(), 'foo' : 'bar', })
#Set the cookie after the response was rendered, and before sending any headers:
return response

A day of setup. A lifetime of insights.

Try Woopra for free. No credit cards. No obligations.