Analytics services for Django projects

Overview

django-analytical Latest version on PyPI

GitHub Actions Test coverage Python versions Software license Gitter chat room Jazzband

The django-analytical application integrates analytics services into a Django project.

Using an analytics service with a Django project means adding Javascript tracking code to the project templates. Of course, every service has its own specific installation instructions. Furthermore, you need to include your unique identifiers, which then end up in the templates. Not very nice.

This application hides the details of the different analytics services behind a generic interface, and keeps personal information and configuration out of the templates. Its goal is to make the basic set-up very simple, while allowing advanced users to customize tracking. Each service is set up as recommended by the services themselves, using an asynchronous version of the Javascript code if possible.

Currently Supported Services

Documentation and Support

The documentation can be found in the docs directory or read online. The source code and issue tracker are generously hosted by GitHub. Bugs should be reported there, whereas for lengthy chats and coding support when implementing new service integrations you're welcome to use our Gitter chat room.

How To Contribute

If you want to help out with the development of django-analytical, by posting detailed bug reports, proposing new features or other analytics services to support, or suggesting documentation improvements, use the issue tracker. If you want to get your hands dirty, great! Clone the repository, make changes and place a pull request. Creating an issue to discuss your plans is useful.

This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidelines.

Comments
  • Create Matomo module; leave Piwik to be deprecated

    Create Matomo module; leave Piwik to be deprecated

    With the rebranding of Piwik to Matomo, this commit:

    • copies the piwik module to matomo and rebrands
    • notes that the piwik module is deprecated
    • updates the javascript to the current Matomo version

    Fixes #132

    opened by sckarlin 24
  • Refactor test suite

    Refactor test suite

    This PR fixes #117,

    • moving the tests out of the analytical package and into a /tests folder,
    • and simplifying setup.py, removing all test set up code.

    Tests should be able to run locally, in the end. Coverage shall be submitted to coveralls from a Travis CI only.

    enhancement help-wanted 
    opened by bittner 16
  • Migrate tests to Pytest plain asserts

    Migrate tests to Pytest plain asserts

    When looking at the code when it is formatted with Black there are a number of cases where it would be a bit more readable if plain pytest asserts were used.

    I've done a few files as an example. Is this wanted? Let me know what you think.

    opened by smithdc1 12
  • SETTING_DELETED isn't working as intended

    SETTING_DELETED isn't working as intended

    Hi Joost,

    I think I've caught a subtle bug in how get_required_setting handles SETTING_DELETED.

    As I understand it, when you set a settings key to SETTING_DELETED via @override_settings you intended for it to raise an AttributeError when retrieved via get_required_setting.

    However, instead of raising an AttributeError in the getattr call -- as I think you intended it -- it's instead failing the regexp check. This line returns a valid DeletedSettingDescriptor object that then proceeds to raise AnalyticalException because it never matches the supplied regexp.

    The end result is all the tests that rely on a missing settings key raising an AnalyticalException pass, but not for the intended reasons.

    I played around with the code a bit and think I figured out a way around it. You can see the commits here: https://github.com/edavis/django-analytical/compare/master...setting-deleted

    2a1e2d3f is the meat of the fix while the other two are more cosmetic but override_settings related. Basically, I check if a value is set to SETTING_DELETED and if it is I delattr it from self.default_settings which is where the value appears to come from. All the tests still pass and stepping through it with a debugger shows it raising an AttributeError as expected in the getattr call in get_required_setting.

    I'm far from an expert on Django's settings machinery, but I think this should do it. If you're interested, feel free to pull from my setting-deleted branch.

    opened by edavis 12
  • Split up test matrix into Python-Django combinations

    Split up test matrix into Python-Django combinations

    A test matrix shall give us a quick answer on what broke when some jobs fail. It's a bit like writing tests: "A test should ideally do just a single thing."

    This change splits up the linear test jobs, mainly defined by their Python version in use, into all Python-Django combinations we test against. Basically, we let GitHub Actions do the same thing as Tox does, when we run the test suite locally:

    $ tox -l
    py36-django22
    py36-django30
    py36-django31
    py37-django22
    py37-django30
    py37-django31
    py38-django22
    py38-django30
    py38-django31
    py39-django22
    py39-django30
    py39-django31
    ...
    
    enhancement 
    opened by bittner 11
  • Enable Intercom for anonymous users

    Enable Intercom for anonymous users

    This removes the check in the code that limits the Intercom widget to authenticated users. I'm not sure why the check was there: Intercom is intended for use with both anonymous and authenticated users.

    This also updates the Intercom tests to add a conventional test_render_internal_ip.

    opened by PiDelport 9
  • Google Analytics _set*SampleRate and _set*CookieTimeout

    Google Analytics _set*SampleRate and _set*CookieTimeout

    I added support for GA's _setSampleRate and _setSiteSpeedSampleRate settings for my needs and then saw _setSessionCookieTimeout and _setVisitorCookieTimeout would be easy to add too.

    I've updated the tests and the docs and thought it might be of interest to other developers. Thanks for this project! Steve

    opened by saschwarz 9
  • Support for intercom.io, fixes inconsistent test fails.

    Support for intercom.io, fixes inconsistent test fails.

    Hey there,

    This is Steven, the guy who also added gaug.es support. This PR adds support for intercom.io, as well as fixing up some annoying inconsistent fails because of json's inconsistent dict rendering order.

    Believe everything's here (tests, docs, etc), if not, ping and I'll add it quickly!

    Thanks again for the great lib, -Steven

    opened by skoczen 9
  • Support for Piwik

    Support for Piwik

    Do you plan to support Piwik? (Has this been requested before?)

    An (elderly) example of JavaScript code used for Piwik is available at e.g. django-piwik-analytics

    opened by bittner 9
  • allow to set identity_func by ANALYTICAL_IDENTITY_FUNC settings

    allow to set identity_func by ANALYTICAL_IDENTITY_FUNC settings

    Google has in it's conditions for enabling UserID requirement, that prohibits sending personal data (such as e-mail address) to analytics. I am using e-mail address as username, so using GTag would break the requirements for me.

    This enables me to set user UUID for the UserID parameter.

    opened by PetrDlouhy 8
  • Google analytics Measurement ID Issue

    Google analytics Measurement ID Issue

    I am getting an error when setting a Measurement ID for GOOGLE_ANALYTICS_GTAG_PROPERTY_ID as my project uses an App+Web property.

    GOOGLE_ANALYTICS_GTAG_PROPERTY_ID setting: must be a string looking like 'UA-XXXXXX-Y': 'G-XXXXXXXXXX'

    I think gtag.js inherently supports both features, and the test case for this should be fixed to take both strings.

    opened by taharushain 8
  • basic mixpanel tracking

    basic mixpanel tracking

    Hi!

    Thanks so much for creating this repo. I'm having trouble doing basic mixpanel tracking.

    I've set up my template html file to look like this:

    {% load analytical %}
    {% load mixpanel %}
    <!DOCTYPE ... >
    <html>
        <head>
            {% analytical_head_top %}
    
            ...
    
            {% analytical_head_bottom %}
        {% mixpanel %}
        </head>
        <body>
            {% analytical_body_top %}
    
            ...
    
            {% analytical_body_bottom %}
        </body>
    </html>
    

    and my settings.py file looks like:

    INSTALLED_APPS = [
        ...
        'analytical',
        ...
    ]
    

    I also added my MIXPANEL_API_TOKEN to settings.py as well, and I have django-analytical==3.1.0 in my requirements.txt file.

    I deployed these changes to a test website, so it's in prod, not dev.

    I think I must be missing something -- should I be making any other code changes to enable tracking?

    Thanks!

    question 
    opened by serenamm 4
  • Add Liveinternet

    Add Liveinternet

    Addition service Liveinternet. Several implementation options have been made as per the documentation:

    1. in the form of a single image combining the counter and the LiveInternet logo
    2. in the form of two images, one of which is a counter (transparent GIF size 1x1), and the other is the LiveInternet logo. This placement method will allow you to insert the code of the invisible counter at the beginning of the page, and the logo - where the design and content of the page allows.
    opened by odi1n 4
  • Remove apparently obsolete setup.cfg

    Remove apparently obsolete setup.cfg

    The setup.cfg file contains configuration data that used to be read by tools like Tox and Sphinx.

    The respective values now appear in pyproject.toml and tox.ini, and it looks like the entire file is hence obsolete.

    I'm not 100% sure whether ReadTheDocs reads the file, but I guess building the docs should work just fine without it.

    opened by bittner 1
  • Matomo ReDoS vulnerability (regex denial of service)

    Matomo ReDoS vulnerability (regex denial of service)

    We have been contacted by junior security researchers who pointed out that one of our regular expressions in the Matomo module makes software using Analytical vulnerable to Regular expression Denial of Service attacks (ReDoS).

    I'm publishing this information in the faith that this vulnerability cannot be exploited easily in our context, because the Matomo server URL is a configuration setting that is not user supplied.

    Details

    From analytical/templatetags/matomo.py, line 20:

    # domain name (characters separated by a dot), optional port, optional URI path, no slash
    DOMAINPATH_RE = re.compile(r'^(([^./?#@:]+\.)*[^./?#@:]+)+(:[0-9]+)?(/[^/?#@:]+)*$')
    

    The problematic bit is the repetition (]+)+) after a piece that induces backtracking.

    Anyone willing to assist in fixing this issue is very welcome! :pray:

    Potential Solution Approaches

    1. Simplify the regular expression (remove or limit the repetition)
    2. Use urllib.parse.urlparse and/or related functions
    3. A combination of 1. and 2.

    Example: (note that urlparse alone seem unsuitable for our use case)

    class MatomoNode(Node):
        def __init__(self):
    
            # avoid ReDoS vulnerability not using a regex with backtracking
            parsable_url = '//' + getattr(settings, 'MATOMO_DOMAIN_PATH', '')
            result = urlparse(parsable_url)
            if result.scheme or (not result.netloc and not result.path):
                # make this fail
    

    Background Reading

    help-wanted security 
    opened by bittner 0
  • Support for Posthog

    Support for Posthog

    posthog.com/ is an open source product analytics platform, comparable to Mixpanel. I think they'd make a great addition and would probably support an integration somehow.

    enhancement 
    opened by janbaykara 1
  • GA not tracking logged in users, GTAG user_id seems to require a different syntax now

    GA not tracking logged in users, GTAG user_id seems to require a different syntax now

    Hi,

    Thank you for this library! I've been using this for Google Analytics but having trouble loading user-id information there.

    It seems like per Google documentation the code required to send user_id information looks like this:

    gtag('config', 'G-XXXXXXXX', {'user_id': 'USER_ID'});
    gtag('set', 'user_properties', { 'crm_id' : 'USER_ID' });
    

    What the library renders is this:

    gtag('set', {'user_id': 'USER_ID'});
    gtag('config', 'G-XXXXXXXX');
    

    Perhaps this is not sending the user id to GA properly? If you think this is the case, I can happily submit a PR to address this.

    opened by keyvanm 4
Owner
Jazzband
We are all part of this
Jazzband
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Feldroy 10k Dec 31, 2022
A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.

Django Sage Painless The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web

sageteam 51 Sep 15, 2022
Django StatusPage - App to display statuspage for your services

Django StatusPage - App to display statuspage for your services

Gorlik 1 Oct 27, 2021
A simple Blog Using Django Framework and Used IBM Cloud Services for Text Analysis and Text to Speech

ElhamBlog Cloud Computing Course first assignment. A simple Blog Using Django Framework and Used IBM Cloud Services for Text Analysis and Text to Spee

Elham Razi 5 Dec 6, 2022
Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project

Django URL Shortener Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project Install this package to your Dja

Rishav Sinha 4 Nov 18, 2021
:couple: Multi-user accounts for Django projects

django-organizations Summary Groups and multi-user account management Author Ben Lopatin (http://benlopatin.com / https://wellfire.co) Status Separate

Ben Lopatin 1.1k Jan 1, 2023
Duckiter will Automatically dockerize your Django projects.

Duckiter Duckiter will Automatically dockerize your Django projects. Requirements : - python version : python version 3.6 or upper version - OS :

soroush safari 23 Sep 16, 2021
Ugly single sign-on for django projects only

django-usso Ugly single sign-on for django projects only. Do you have many django apps with different users? Do you want to use only one of those apps

Erwin Feser 1 Mar 1, 2022
Django Fett is an incomplete code generator used on several projects

Django Fett Django Fett is an incomplete code generator used on several projects. This is an attempt to clean it up and make it public for consumption

Jeff Triplett 6 Dec 31, 2021
Meta package to combine turbo-django and stimulus-django

Hotwire + Django This repository aims to help you integrate Hotwire with Django ?? Inspiration might be taken from @hotwired/hotwire-rails. We are sti

Hotwire for Django 31 Aug 9, 2022
django-reversion is an extension to the Django web framework that provides version control for model instances.

django-reversion django-reversion is an extension to the Django web framework that provides version control for model instances. Requirements Python 3

Dave Hall 2.8k Jan 2, 2023
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.

Django-environ django-environ allows you to use Twelve-factor methodology to configure your Django application with environment variables. import envi

Daniele Faraglia 2.7k Jan 7, 2023
Django project starter on steroids: quickly create a Django app AND generate source code for data models + REST/GraphQL APIs (the generated code is auto-linted and has 100% test coverage).

Create Django App ?? We're a Django project starter on steroids! One-line command to create a Django app with all the dependencies auto-installed AND

imagine.ai 68 Oct 19, 2022
django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

django-quill-editor django-quill-editor makes Quill.js easy to use on Django Forms and admin sites No configuration required for static files! The ent

lhy 139 Dec 5, 2022
A Django chatbot that is capable of doing math and searching Chinese poet online. Developed with django, channels, celery and redis.

Django Channels Websocket Chatbot A Django chatbot that is capable of doing math and searching Chinese poet online. Developed with django, channels, c

Yunbo Shi 8 Oct 28, 2022
A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a unique id.

Django-URL-Shortener A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a uni

Rohini Rao 3 Aug 8, 2021
Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot. A fully Django starter project.

Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot ?? Features A Django stater project with fully basic requirements for a production-ready

null 8 Jun 27, 2022
pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-dev 1.1k Dec 14, 2022
APIs for a Chat app. Written with Django Rest framework and Django channels.

ChatAPI APIs for a Chat app. Written with Django Rest framework and Django channels. The documentation for the http end points can be found here This

Victor Aderibigbe 18 Sep 9, 2022