A Django app to integrate Fathom Analytics into your project
Project description
django-usefathom
Fathom Analytics integration with Django projects. Provides ability to integrate page view tracking and goal reporting.
Installation
Install the package:
pip install django-usefathom
Add usefathom
to your settings.py
file:
INSTALLED_APPS = [
# ...
"usefathom",
# ...
]
Add template processor to your settings.py
file:
TEMPLATES = [
{
# ....
"OPTIONS": {
"context_processors": [
# ...
"usefathom.context_processors.usefathom",
# ...
],
},
},
]
Add your fathom site id to your settings.py
file:
FATHOM_SITE_ID = "XXXX1234"
Include tracking snippet in your templates:
{% include "usefathom/usefathom.html" %}
From this point your site visits will be tracked.
Custom domain for Fathom Analytics script
If you want to use the custom domain for Fathom Analytics add to your settings.py
:
FATHOM_SCRIPT_URL=https://cname.yourdomain.com/script.js
Goal Tracking
Python
Optionally, add your goals dictionary to your settings.py
file:
FATHOM_GOALS = {
"registration": "XXXO9X",
"add_to_card": "YYYO9X,
# ....
}
Now if you want to report a goal from your backend service to Fathom analytics:
from usefathom.api import track
def some_view(request, *args, **kwargs):
# anywhere you have request object, most likely views are a good place for this
track(request, "add_to_card", "2999") # Third parameter is optional, attaches the monetary value to the goal. 29.99 in example
And the goal will be reported to Fathom analytics on the next page load.
HTML+JS
You can use template tags to track the goals from the html. It's useful when tracking external link clicks, etc.
{% load fathom }
......with link
<a href="https://go-somewhere.com/link" {% click_goal "somewhere_link_clicked" 100 %}>Go somewhere?</a>
......with form
<form method="POST" {% submit_goal "registration_submit" %}>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_usefathom-1.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de2a5cbd02fd6f7255f62f95310b5b5fbdb3367901701b8bdb278faf95a09c73 |
|
MD5 | c60b082e8be3c7696b288201c5fbf977 |
|
BLAKE2b-256 | 56ec4f07a391b1a499c6815b3bb687fd7f3ca9ffe28e9c4efaaa4f9a6d1e3219 |