Skip to main content

Django Sendgrid Tracking

Travis codecov Python Versions PyPI Version MIT licensed Documentation Status

Sendgrid Mail tracking for Django, store sendgrid tracking info into django models.

This library allows to track the email sent using Sendgrid by storing information collected from a webhook into django models.

Table of Contents

Installation

Prerequisites

  • Python version 3.6+

  • Sendgrid account and API configuration

Environment Variables

This library uses django-sendgrid-v5 which requires the following in your settings.py:

EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
SENDGRID_API_KEY = os.environ["SENDGRID_API_KEY"]

You can find more information and other settings here

Install package

Install the library with pip

$ pip install django-sendgrid-tracking

Quick Start

Below the steps to start using django-sendgrid-tracking in your django project using your sendgrid account.

Enable django

To enable django_sendgrid_tracking in your project you to add it to INSTALLED_APPS in your projects settings.py file

INSTALLED_APPS = (
    ...
    'django_sendgrid_tracking'
    ...
)

Run django migrate to create django-sendgrid-tracking related models

$ python manage.py migrate

In addition to that you need to expose for sendgrid the webhook endpoint

from django.conf.urls import url
from django_sendgrid_tracking import views

...
urlpatterns = [
    ...
    url(r'sendgrid_webhook', views.event_hooks, name='sendgrid_webhook'),
    ...
]

Enable sendgrid

Now you need to provide this endpoint URL to Sendgrid from the console (Setting -> Mail Settings -> Event WebHook):

sendgrid-webhook-configuration

In this case your webhook would be available at http://www.mywebsite.com/sendgrid_webhook/ N.B. remember to append a slash at the end of it since it will be a POST request

Use cases

The most simple use case would be to analyse internal statics or troubleshoot pitfall in the application flow. As an example we can see for which reason a particular user didn’t confirm the email address

e.g.

sent_email = SentMail.object.filter(
    to_email__mail=user.mail,
    categories__category_code='confirm_email'
)
print(sent_email.open_flag)
# True the user opened the email
print(sent_email.click_flag)
# False the user didn't click on the confirmation link
# Maybe something is wrong with the content of the email?

Another use case is in the case of referral program we can show the user the status of the sent invitation

e.g.

use-case-referral

(example from https://www.omologherifiuti.it)

About

django-sendgrid-tracking is a library extracted from different website implemented by the author in django

If you’ve instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Any contribution is appreciated!! (see CONTRIBUTING)

License

The MIT License (MIT)

Metadata

Release files for django-sendgrid-tracking 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sendgrid-tracking 1.0.6
File Size Uploaded
django-sendgrid-tracking-1.0.6.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-sendgrid-tracking 1.0.6
File Interpreter ABI Platform
django_sendgrid_tracking-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 28.8 kB

Release files / django-sendgrid-tracking-1.0.6.tar.gz

Download URL django-sendgrid-tracking-1.0.6.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d02ed36b49a20f7782120f996a1421e4bd7882a71ac439db36a6d4c94e655623
BLAKE2b-256 checksum
How to use checksums
0d089f017c366a794ef59adc0e929a105852559f41b910d412b9885ca3555e26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Release files / django_sendgrid_tracking-1.0.6-py3-none-any.whl

Download URL django_sendgrid_tracking-1.0.6-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab914c4c94881575dbcb7f4f983b0877d08185f6b14731301b0fcf94e258d959
BLAKE2b-256 checksum
How to use checksums
3927d19d079771b14c45cb7fe502730516c2376987ddfea98fc8641d27c749c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.3

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page