Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error for Matomo (return code 500-php/server error) - no parent… #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions analytical/templatetags/analytical.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
from __future__ import absolute_import

import logging
from importlib import import_module

from django import template
from django.template import Node, TemplateSyntaxError
from importlib import import_module

from analytical.utils import AnalyticalException


TAG_LOCATIONS = ['head_top', 'head_bottom', 'body_top', 'body_bottom']
TAG_POSITIONS = ['first', None, 'last']
TAG_MODULES = [
Expand Down Expand Up @@ -83,7 +82,7 @@ def add_node_cls(location, node, position=None):
try:
module.contribute_to_analytical(add_node_cls)
except AnalyticalException as e:
logger.debug("not loading tags from '%s': %s", path, e)
logger.trace("django-analytical settings not (or not properly) configured for '%s': %s", path, e)
for location in TAG_LOCATIONS:
template_nodes[location] = sum((template_nodes[location][p]
for p in TAG_POSITIONS), [])
Expand Down
5 changes: 4 additions & 1 deletion analytical/templatetags/chartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from analytical.utils import is_internal_ip, disable_html, get_required_setting


USER_ID_RE = re.compile(r'^\d+$')
INIT_CODE = """<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>"""
SETUP_CODE = """
Expand Down Expand Up @@ -57,6 +56,8 @@ def chartbeat_top(parser, token):

class ChartbeatTopNode(Node):
def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
if is_internal_ip(context):
return disable_html(INIT_CODE, "Chartbeat")
return INIT_CODE
Expand All @@ -83,6 +84,8 @@ def __init__(self):
"must be (a string containing) a number")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
config = {'uid': self.user_id}
domain = _get_domain(context)
if domain is not None:
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/clickmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import is_internal_ip, disable_html, get_required_setting


CLICKMAP_TRACKER_ID_RE = re.compile(r'^\w+$')
TRACKING_CODE = """
<script type="text/javascript">
Expand Down Expand Up @@ -50,6 +50,8 @@ def __init__(self):
"must be an alphanumeric string")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = TRACKING_CODE % {'tracker_id': self.tracker_id}
if is_internal_ip(context, 'CLICKMAP'):
html = disable_html(html, 'Clickmap')
Expand Down
6 changes: 4 additions & 2 deletions analytical/templatetags/clicky.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import json
import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import get_identity, is_internal_ip, disable_html, \
get_required_setting

get_required_setting
Comment on lines 13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about?

from analytical.utils import (
    disable_html,
    get_identity,
    get_required_setting,
    is_internal_ip,
)


SITE_ID_RE = re.compile(r'^\d+$')
TRACKING_CODE = """
Expand Down Expand Up @@ -56,6 +56,8 @@ def __init__(self):
"must be a (string containing) a number")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
custom = {}
for dict_ in context:
for var, val in dict_.items():
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/crazy_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import is_internal_ip, disable_html, get_required_setting


ACCOUNT_NUMBER_RE = re.compile(r'^\d+$')
SETUP_CODE = '<script type="text/javascript" src="{placeholder_url}">' \
'</script>'.\
Expand Down Expand Up @@ -45,6 +45,8 @@ def __init__(self):
)

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = SETUP_CODE % {
'account_nr_1': self.account_nr[:4],
'account_nr_2': self.account_nr[4:],
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/facebook_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import get_required_setting, is_internal_ip, disable_html


FACEBOOK_PIXEL_HEAD_CODE = """\
<script>
!function(f,b,e,v,n,t,s)
Expand Down Expand Up @@ -70,6 +70,8 @@ def __init__(self):
)

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = self.code_template % {'FACEBOOK_PIXEL_ID': self.pixel_id}
if is_internal_ip(context, 'FACEBOOK_PIXEL'):
return disable_html(html, 'Facebook Pixel')
Expand Down
3 changes: 3 additions & 0 deletions analytical/templatetags/gauges.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import is_internal_ip, disable_html, get_required_setting
Expand Down Expand Up @@ -52,6 +53,8 @@ def __init__(self):
"must be a string looking like 'XXXXXXX'")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = TRACKING_CODE % {'site_id': self.site_id}
if is_internal_ip(context, 'GAUGES'):
html = disable_html(html, 'Gauges')
Expand Down
2 changes: 2 additions & 0 deletions analytical/templatetags/google_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(self):
"must be a string looking like 'UA-XXXXXX-Y'")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
commands = self._get_domain_commands(context)
commands.extend(self._get_custom_var_commands(context))
commands.extend(self._get_other_commands(context))
Expand Down
3 changes: 3 additions & 0 deletions analytical/templatetags/google_analytics_gtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import (
Expand Down Expand Up @@ -51,6 +52,8 @@ def __init__(self):
"must be a string looking like 'UA-XXXXXX-Y'")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = SETUP_CODE.format(
property_id=self.property_id,
)
Expand Down
3 changes: 3 additions & 0 deletions analytical/templatetags/google_analytics_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import decimal
import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

Expand Down Expand Up @@ -62,6 +63,8 @@ def __init__(self):
"must be a string looking like 'UA-XXXXXX-Y'")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
import json
create_fields = self._get_domain_fields(context)
create_fields.update(self._get_other_create_fields(context))
Expand Down
6 changes: 4 additions & 2 deletions analytical/templatetags/gosquared.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import get_identity, \
is_internal_ip, disable_html, get_required_setting

is_internal_ip, disable_html, get_required_setting

TOKEN_RE = re.compile(r'^\S+-\S+-\S+$')
TRACKING_CODE = """
Expand Down Expand Up @@ -55,6 +55,8 @@ def __init__(self):
"must be a string looking like XXX-XXXXXX-X")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
configs = [TOKEN_CODE % self.site_token]
identity = get_identity(context, 'gosquared', self._identify)
if identity:
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/hotjar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import get_required_setting, is_internal_ip, disable_html


HOTJAR_TRACKING_CODE = """\
<script>
(function(h,o,t,j,a,r){
Expand Down Expand Up @@ -52,6 +52,8 @@ def __init__(self):
)

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = HOTJAR_TRACKING_CODE % {'HOTJAR_SITE_ID': self.site_id}
if is_internal_ip(context, 'HOTJAR'):
return disable_html(html, 'Hotjar')
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/hubspot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import is_internal_ip, disable_html, get_required_setting


PORTAL_ID_RE = re.compile(r'^\d+$')
TRACKING_CODE = """
<!-- Start of Async HubSpot Analytics Code -->
Expand Down Expand Up @@ -48,6 +48,8 @@ def __init__(self):
"must be a (string containing a) number")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
html = TRACKING_CODE % {'portal_id': self.portal_id}
if is_internal_ip(context, 'HUBSPOT'):
html = disable_html(html, 'HubSpot')
Expand Down
8 changes: 5 additions & 3 deletions analytical/templatetags/intercom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import hashlib
import hmac
import json
import sys
import re
import sys
import time

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import disable_html, get_required_setting, \
is_internal_ip, get_user_from_context, get_identity, \
get_user_is_authenticated
is_internal_ip, get_user_from_context, get_identity, \
get_user_is_authenticated
Comment on lines 17 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't isort and black like something like this better?

from analytical.utils import (
    disable_html,
    get_identity,
    get_required_setting,
    get_user_from_context,
    get_user_is_authenticated,
    is_internal_ip,
)


APP_ID_RE = re.compile(r'[\da-z]+$')
TRACKING_CODE = """
Expand Down Expand Up @@ -126,6 +126,8 @@ def _get_custom_attrs(self, context):
return params

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
params = self._get_custom_attrs(context)
params["app_id"] = self.app_id
html = TRACKING_CODE % {
Expand Down
4 changes: 3 additions & 1 deletion analytical/templatetags/kiss_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import get_identity, get_required_setting


ACCOUNT_NUMBER_RE = re.compile(r'^\d+$')
SITE_CODE_RE = re.compile(r'^[\w]+$')
SETUP_CODE = """
Expand Down Expand Up @@ -51,6 +51,8 @@ def __init__(self):
"must be a string containing three characters")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
commands = []
identity = get_identity(context, 'kiss_insights')
if identity is not None:
Expand Down
6 changes: 4 additions & 2 deletions analytical/templatetags/kiss_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import json
import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import is_internal_ip, disable_html, get_identity, \
get_required_setting

get_required_setting

API_KEY_RE = re.compile(r'^[0-9a-f]{40}$')
TRACKING_CODE = """
Expand Down Expand Up @@ -66,6 +66,8 @@ def __init__(self):
"must be a string containing a 40-digit hexadecimal number")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
commands = []
identity = get_identity(context, 'kiss_metrics')
if identity is not None:
Expand Down
5 changes: 3 additions & 2 deletions analytical/templatetags/matomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@

from __future__ import absolute_import

import re
from collections import namedtuple
from itertools import chain
import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError

from analytical.utils import (is_internal_ip, disable_html,
get_required_setting, get_identity)


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

Expand Down Expand Up @@ -84,6 +83,8 @@ def __init__(self):
"must be a (string containing a) number")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
custom_variables = context.get('matomo_vars', ())

complete_variables = (var if len(var) >= 4 else var + (DEFAULT_SCOPE,)
Expand Down
6 changes: 4 additions & 2 deletions analytical/templatetags/mixpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import json
import re

from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError
from django.utils.safestring import mark_safe

from analytical.utils import is_internal_ip, disable_html, get_identity, \
get_required_setting

get_required_setting

MIXPANEL_API_TOKEN_RE = re.compile(r'^[0-9a-f]{32}$')
TRACKING_CODE = """
Expand Down Expand Up @@ -52,6 +52,8 @@ def __init__(self):
"must be a string containing a 32-digit hexadecimal number")

def render(self, context):
if settings.get("DISABLE_TRACKING_CODE", False):
return ""
commands = []
identity = get_identity(context, 'mixpanel')
if identity is not None:
Expand Down
Loading