Comments (13)
I just discovered that the generic tags ({% analytical_head_top %}
, etc.) work differently than the specific tags (e.g. {% piwik %}
). Unlike the specific tags, which fail with an error if the corresponding configuration is unavailable or invalid, the generic tags fail silently if there are no analytics services configured in the settings. I think the generic tags' behavior is better, and makes it easy to use django-analytical in development, staging, and production environments.
from django-analytical.
We should fix the implementation. Development should be easy, ideally intuitive.
from django-analytical.
I think you should use the INTERNAL_IPS
settings property for development. This feature is covered by the tests, so it should work reliably. See Django's Settings documentation for details on INTERNAL_IPS
, the default value for ANALYTICAL_INTERNAL_IPS
.
The sentence "If you do not set the site ID the tracking code will not be rendered" in the documentation should be removed as SITE_ID
is a required setting. I fear it would be confusing to make it not being rendered when the SITE_ID
is empty---which could be by error. -- Sorry for the mistake in the docs.
from django-analytical.
I have just noticed the same problem as @garrettr . INTERNAL_IPS
does not solve the problem - there should be some settings variable disabling the Piwik tag.
What INTERNAL_IPS
scenario is missing is that when one has the dev server running on some machine and a team of developers/testers sending the requests from their local machines or mobile devices one would have to register all that devices IPs in the '[ANALYTICAL_]INTERNAL_IPS` var. This should not be the desired behavior.
I think, the very simple solution for this could be:
from django.conf import settings
inanalytical/templatetags/piwik.py
- and then update the
PiwikNode.render
method:
if is_internal_ip(context, 'PIWIK') or settings.DEBUG:
html = disable_html(html, 'Piwik')
I would however, opt for some more explicit settings variable like ANALYTICAL_ENABLED
(=True by default). This (or similar) solution should be applied to all the other tags related to other analytical services.
What do you think about it @bittner
from django-analytical.
@sebzur Difficult to say. A new setting to disable analytical globally may be practical. Though, I'm not a big fan of polluting the code with additional settings. "There should be one-- and preferably only one --obvious way to do it." (PEP 20)
The beauty of INTERNAL_IPS
is that this is a functionality provided and used by the Django framework itself. I've not seen any hints in the documentation whether specifying IP ranges is possible, which may solve the "may IPs to add" issue; it seems not to be.
@garrettr If the generic and specific tags behave differently, that's a problem. -- Do they really? Why? @jcassee, can you tell?
I'm not a big fan of silent errors. An erroneous application should fail to tell us we need to fix a problem. "Errors should never pass silently. Unless explicitly silenced." (PEP 20)
from django-analytical.
Could you not simply check a setting in your base template(s)? For example:
{% if not settings.DEBUG %}{% analytical_body_bottom %}{% endif %}
from django-analytical.
We're using google analytics. Normally when we don't want something to run we would use
{% if not debug %} ...stuff... {% endif %}
However, that doesn't appear to be working when using this plugin like so:
{% if not debug %}
{% google_analytics %}
{% endif %}
doesn't prevent the plugin from loading and attempting to find the ga variable, producing:
AnalyticalException at / GOOGLE_ANALYTICS_PROPERTY_ID setting is not set
Why is the plugin still rendering? That is quite absurd.
from django-analytical.
However, using:
{% if not debug %}
{% analytical_head_top %}{% analytical_head_bottom %}
{% endif %}
does return the expected behavior. Why is this any different? I'd prefer to stick with just the google analytics tag since it's the only library we import.
from django-analytical.
Sorry if this is not 100% the answer you want. If there is a bug or irritating behavior this deserves to be fixed. I agree. Anyway, here are my two cents on your side comment:
I'd prefer to stick with just the google analytics tag since it's the only library we import.
If you restrict yourself to a single provider what is the benefit of this? Does your code get any more readable? Do you have any performance benefits? Those are the questions you should ask yourself.
And if one day the unlikely event occurs that you actually want to switch to another analytics provider, hey, then you get all the actual, real benefits of this Python package. Think about it. I would advise on actually using this package for the reason it was designed for.
from django-analytical.
The exception you mention above is raised at analytical.utils, line 25, which in your case probably comes from templatetags.google_analytics, line 82 via line 77 in the same file.
I would guess you don't have the tag loading enclosed in an if-clause on top of your template.
from django-analytical.
That's a fair enough response, and using the generic import is doing the trick for us. I suppose that I just expected it to behave the same way. Since it doesn't behave the same way, you might consider adding some documentation about the caveats of using the individual imports.
from django-analytical.
Mind to make a PR for this?
from django-analytical.
BTW, as I suspected, the reason why the generic template tag works and the single one throws an exception is such that the generic tag ignores exceptions that happen in the single implementations. Exceptions that occur in the contribute_to_analytical
function pass silently (for a valid reason) this way.
When you do things "the manual way" you also have to make sure yourself that either the exception is silenced or, better, all preconditions for the code being successfully executed (or not being executed at all!) must be met. As I pointed out earlier you probably had a {% load google_analytics %}
in your template that was not covered by any {% if not debug %}
clause, and according to the exception you don't seem to set the GOOGLE_ANALYTICS_PROPERTY_ID
in your Django settings
when debug
is True
.
If this is all true then there's little to document. Then the implementation behaves as we should expect.
from django-analytical.
Related Issues (20)
- Gitter Sidecar integration
- New release and follow-up tasks HOT 1
- Clickmap link in README links to spammy website HOT 2
- Support for Google Analytics 4 tags HOT 9
- Default value for SECURE_REFERRER_POLICY in Django 3.1 breaks Clicky HOT 2
- how to set enhanced eCommerce in google analytics HOT 2
- how to set identity_func HOT 3
- Ability to push custom commands to Matomo
- Respecting Consent ( Possible fix for #141 ) HOT 6
- Ability to pass FACEBOOK_PIXEL_ID directly in template tag HOT 1
- GA not tracking logged in users, GTAG user_id seems to require a different syntax now HOT 4
- support for python 3.10 HOT 1
- Rename default branch (master ➜ main) HOT 1
- Support for Posthog HOT 1
- Allow to set a custom location for google analytics js - support for proxy HOT 2
- Matomo ReDoS vulnerability (regex denial of service)
- Latest docs must build from `main` (not `master`) HOT 3
- basic mixpanel tracking HOT 4
- Setting google_analytics_gtag_identity does not work HOT 3
- Usage in Docker HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-analytical.