bruth / django-tracking2

django-tracking2 tracks the length of time visitors and registered users spend on your site. Although this will work for websites, this is more applicable to web _applications_ with registered users. This does not replace (nor intend) to replace client-side analytics which is great for understanding aggregate flow of page views.
BSD 2-Clause "Simplified" License
205 stars 67 forks source link

Can't track users based on if user accepts or rejects tracking (Close this please -- I solved it) #79

Closed SilverStrings024 closed 4 years ago

SilverStrings024 commented 4 years ago

I need to give the user the ability to not be tracked but can't seem to find a way to exclude them from the tracker. Is there a way to do this or should I try to modify the package to do so? If I do get it to be able to exclude users, should I submit a PR? This is a very useful package and I'd like to help improve it if I can.

SilverStrings024 commented 4 years ago

I made a function in my tools file (Holds all tools to make my life easier) called get_sessions() that gets and/or sets a session key called 'track'. Inside of the "_should_track()" function in the "VisitorTrackingMiddleware" I did a check (using check_sessions() ) to ensure the key exists after the check for sessions install and before any other checks, if so I would return True or False depending on its status, if it's not in session data (return of the function would be None in this case) then it would automatically set it.

Should I make a pull request? It's not a big change and can be easily expanded to use cookies or sessions and the check_session() function can be used to get, set, or delete a cookie or session whether it connects to tracking or not. It can even be used to include some javascript/ajax to make its own accept/reject banners.