### Install django-analytical using easy_install Source: https://github.com/jazzband/django-analytical/blob/main/docs/tutorial.rst Installs the latest stable version of django-analytical from the Python Package Index using the easy_install command. This is the primary method for initial setup. ```bash $ easy_install django-analytical ``` -------------------------------- ### Install django-analytical Python Package Source: https://github.com/jazzband/django-analytical/blob/main/docs/install.rst Installs the django-analytical package using easy_install or by cloning the source code from GitHub and running the setup script. This makes the package available in your Python environment. ```bash $ easy_install django-analytical ``` ```bash $ git clone https://github.com/jazzband/django-analytical.git $ cd django-analytical $ python setup.py install ``` -------------------------------- ### Install Django Analytical Source: https://context7.com/jazzband/django-analytical/llms.txt Install the django-analytical package using pip. This is the first step to integrating analytics into your Django project. ```bash pip install django-analytical ``` -------------------------------- ### Set Visitor Email using Django Context Processor Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/snapengage.rst Provides an example of a Django context processor to dynamically set the visitor's email address for SnapEngage. This processor attempts to retrieve a business email from the user's profile. ```python from django.core.exceptions import ObjectDoesNotExist def set_snapengage_email(request): try: profile = request.user.get_profile() return {'snapengage_email': profile.business_email} except (AttributeError, ObjectDoesNotExist): return {} ``` -------------------------------- ### Record Event in KISSmetrics via Context Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_metrics.rst Record an event in KISSmetrics by setting the 'kiss_metrics_event' variable in the template context. This example records a 'Signed Up' event with associated properties like 'Plan' and 'Amount'. The output script will include the JavaScript event. ```python from django.template import RequestContext context = RequestContext({ 'kiss_metrics_event': ['Signed Up', {'Plan' : 'Pro', 'Amount' : 9.99}], }) return some_template.render(context) ``` -------------------------------- ### Gaug.es JavaScript Tracking Code Example Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/gauges.rst An example of the JavaScript code generated by the Gaug.es service, which includes the site ID for tracking. This code is typically embedded in HTML to initiate real-time tracking. ```javascript var _gauges = _gauges || []; (function() { var t = document.createElement('script'); t.type = 'text/javascript'; t.async = true; t.id = 'gauges-tracker'; t.setAttribute('data-site-id', 'XXXXXXXXXXXXXXXXXXXXXXX'); t.src = '//secure.gaug.es/track.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t, s); })(); ``` -------------------------------- ### Complete Production Django Settings for Analytics Source: https://context7.com/jazzband/django-analytical/llms.txt This comprehensive Python example shows a production-ready Django settings configuration. It enables multiple analytics services like Google Analytics, Mixpanel, Hotjar, Intercom, Matomo, and Facebook Pixel, along with security settings and environment variable integration. ```python # settings.py - Production configuration import os INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'analytical', # ... your apps ] # Site framework for automatic domain detection SITE_ID = 1 # Global analytics settings ANALYTICAL_AUTO_IDENTIFY = True ANALYTICAL_INTERNAL_IPS = os.environ.get('INTERNAL_IPS', '').split(',') # Google Analytics 4 GOOGLE_ANALYTICS_GTAG_PROPERTY_ID = os.environ.get('GA_PROPERTY_ID') # Mixpanel MIXPANEL_API_TOKEN = os.environ.get('MIXPANEL_TOKEN') # Hotjar HOTJAR_SITE_ID = os.environ.get('HOTJAR_SITE_ID') # Intercom with identity verification INTERCOM_APP_ID = os.environ.get('INTERCOM_APP_ID') INTERCOM_HMAC_SECRET_KEY = os.environ.get('INTERCOM_HMAC_SECRET') # Self-hosted Matomo MATOMO_DOMAIN_PATH = os.environ.get('MATOMO_DOMAIN', 'analytics.example.com') MATOMO_SITE_ID = os.environ.get('MATOMO_SITE_ID', '1') MATOMO_DISABLE_COOKIES = True # GDPR compliance # Facebook Pixel for ads FACEBOOK_PIXEL_ID = os.environ.get('FB_PIXEL_ID') ``` -------------------------------- ### Configure KISSmetrics Properties in Django Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_metrics.rst This snippet shows how to set user properties for KISSmetrics within a Django template context. It assumes the django-analytical library is installed and configured. The properties are passed as a dictionary to the context, which is then rendered by the template. ```python context = RequestContext(request, {'user': request.user, 'kiss_metrics_properties': {'gender': 'Male'}, }) return some_template.render(context) ``` -------------------------------- ### Add Visitor Status Information (Python/Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/olark.rst This example demonstrates how to pass additional information about a visitor to Olark operators using the 'olark_status' context variable. This variable can be a string or a list of strings, which will appear in the operator buddy list. This is useful for providing context like cart contents or order value. ```python from django.template import RequestContext # Assuming 'cart' is an object with 'item_count' and 'total_value' context = RequestContext({'olark_status': [ 'has %d items in cart' % cart.item_count, 'value of items is $%0.2f' % cart.total_value, ]}) return some_template.render(context) ``` -------------------------------- ### Track Custom Data with Template Context Variables Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/spring_metrics.rst This Python example shows how to track additional custom data, such as transaction IDs or user information, by setting `spring_metrics_X` template context variables. It demonstrates tracking both revenue and an order ID. ```python from django.template import RequestContext context = RequestContext({ 'spring_metrics_revenue': '30.53', 'spring_metrics_order_id': '15445', }) return some_template.render(context) ``` -------------------------------- ### Pass User Identity to KISSmetrics via Context Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_metrics.rst This example demonstrates how to pass a user's identity to KISSmetrics by adding a variable to the template context. The 'kiss_metrics_identity' variable takes precedence if both it and 'analytical_identity' are set. This allows tying events to specific users. ```python from django.template import RequestContext context = RequestContext({'kiss_metrics_identity': identity}) return some_template.render(context) ``` -------------------------------- ### Set User Variables for Click Segmentation (Django View) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/crazy_egg.rst Example of setting user variables (crazy_egg_var1 through crazy_egg_var5) in a Django view's context. These variables allow for segmenting click analysis in Crazy Egg. Note that context processors can also be used. ```python from django.template import RequestContext context = RequestContext({'crazy_egg_var1': 'red', 'crazy_egg_var2': 'male'}) return some_template.render(context) ``` -------------------------------- ### Mixpanel People Properties Context Processor Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/mixpanel.rst This Python code example demonstrates a Django context processor for sending detailed user properties to Mixpanel. Instead of a simple identity string, it sends a dictionary containing 'id' and other custom 'people properties' like 'last_login' and 'date_joined'. ```python def identify(request): try: return { 'mixpanel_identity': { 'id': request.user.id, 'last_login': str(request.user.last_login), 'date_joined': str(request.user.date_joined), } } except AttributeError: return {} ``` -------------------------------- ### Context Processor for User Identity Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_metrics.rst A context processor can be used to automatically derive and pass the user's identity to KISSmetrics. This example uses the user's email address. Ensure this processor is added to your TEMPLATE_CONTEXT_PROCESSORS in settings.py. ```python def identify(request): try: return {'kiss_metrics_identity': request.user.email} except AttributeError: return {} ``` -------------------------------- ### Set Custom Clicky Data in View (Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/clicky.rst This example shows how to pass custom data to Clicky from a Django view. By setting context variables like 'clicky_title', you can customize the data tracked by Clicky. This data is then available to the {% clicky %} template tag. ```python from django.template import RequestContext context = RequestContext({'clicky_title': 'A better page title'}) return some_template.render(context) ``` -------------------------------- ### Configure KISSinsights Account and Site Code in Django Settings Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_insights.rst This code shows how to set the `KISSINSIGHTS_ACCOUNT_NUMBER` and `KISS_INSIGHTS_WEBSITE_CODE` in your Django project's `settings.py` file. These values are crucial for the `kiss_insights` tag to render the correct JavaScript survey code. Obtain these values from the KISSinsights website's code installation page. ```python KISSINSIGHTS_ACCOUNT_NUMBER = 'XXXXX' KISSINSIGHTS_SITE_CODE = 'XXX' ``` -------------------------------- ### Set Woopra Idle Timeout (Django Settings) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/woopra.rst Customize the Woopra visitor timeout period (in milliseconds) by setting the WOOPRA_IDLE_TIMEOUT variable in settings.py. The default is 4 minutes. Example sets it to 10 minutes. ```python WOOPRA_IDLE_TIMEOUT = 10 * 60 * 1000 ``` -------------------------------- ### Add 'analytical' to Django INSTALLED_APPS Source: https://github.com/jazzband/django-analytical/blob/main/docs/install.rst Configures your Django project to use the 'analytical' application by adding it to the INSTALLED_APPS list in your settings.py file. This step is necessary for django-analytical to function within your project. ```python INSTALLED_APPS = [ ... 'analytical', ... ] ``` -------------------------------- ### Pass Performable User Identity via Django Context Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/performable.rst This example shows how to pass user identity information to Performable from your Django views. You can add either 'performable_identity' or 'analytical_identity' to the RequestContext. 'performable_identity' takes precedence if both are set. ```python from django.template import RequestContext context = RequestContext({'performable_identity': identity}) return some_template.render(context) ``` -------------------------------- ### Configure Clicky Site ID and Crazy Egg Account Number Source: https://github.com/jazzband/django-analytical/blob/main/docs/tutorial.rst Sets the Clicky Site ID and Crazy Egg Account Number in the project's settings.py file. These credentials are required for django-analytical to send data to the respective analytics services. ```python CLICKY_SITE_ID = 'xxxxxxxx' CRAZY_EGG_ACCOUNT_NUMBER = 'xxxxxxxx' ``` -------------------------------- ### Pass Custom Data to Woopra via Template Context (Django View) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/woopra.rst This example shows how to pass custom data, like 'woopra_cart_value', from your Django view to the template context. The 'woopra' tag can then automatically send this data to Woopra. ```python from django.template import RequestContext context = RequestContext({'woopra_cart_value': cart.total_price}) return some_template.render(context) ``` -------------------------------- ### Load and Use Service-Specific Template Tags in HTML Source: https://context7.com/jazzband/django-analytical/llms.txt This snippet demonstrates how to load and use individual service-specific template tags within an HTML file. It shows the loading of tags for Google Analytics, Mixpanel, Hotjar, and Intercom, followed by their placement within the HTML structure. ```html {% load google_analytics_gtag %} {% load mixpanel %} {% load hotjar %} {% load intercom %} {% google_analytics_gtag %} {% hotjar %} {% mixpanel %}

My Application

{% intercom %} ``` -------------------------------- ### Load and Insert SnapEngage Template Tag in Django Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/snapengage.rst This snippet demonstrates how to load the SnapEngage template tag library and insert the SnapEngage tag into your Django templates. It's recommended to place this in your base template to ensure it appears on every tracked page. No external dependencies are required beyond Django's template system. ```html {% load snapengage %} ... {% snapengage %} ``` -------------------------------- ### Configure Analytics Services in settings.py Source: https://github.com/jazzband/django-analytical/blob/main/docs/install.rst Enables specific analytics services by defining their required settings in your Django project's settings.py file. Each service has a unique set of configuration variables. ```python # Chartbeat CHARTBEAT_USER_ID = '12345' # Clickmap CLICKMAP_TRACKER_CODE = '12345678....912' # Clicky CLICKY_SITE_ID = '12345678' # Crazy Egg CRAZY_EGG_ACCOUNT_NUMBER = '12345678' # Facebook Pixel FACEBOOK_PIXEL_ID = '1234567890' # Gaug.es GAUGES_SITE_ID = '0123456789abcdef0123456789abcdef' # Google Analytics (legacy) GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-1234567-8' # Google Analytics (gtag.js) GOOGLE_ANALYTICS_GTAG_PROPERTY_ID = 'UA-1234567-8' # Google Analytics (analytics.js) GOOGLE_ANALYTICS_JS_PROPERTY_ID = 'UA-12345678-9' # HubSpot HUBSPOT_PORTAL_ID = '1234' HUBSPOT_DOMAIN = 'somedomain.web101.hubspot.com' # Intercom INTERCOM_APP_ID = '0123456789abcdef0123456789abcdef01234567' # KISSinsights KISS_INSIGHTS_ACCOUNT_NUMBER = '12345' KISS_INSIGHTS_SITE_CODE = 'abc' # KISSmetrics KISS_METRICS_API_KEY = '0123456789abcdef0123456789abcdef01234567' # Lucky Orange LUCKYORANGE_SITE_ID = '123456' # Matomo (formerly Piwik) MATOMO_DOMAIN_PATH = 'your.matomo.server/optional/path' MATOMO_SITE_ID = '123' # Mixpanel MIXPANEL_API_TOKEN = '0123456789abcdef0123456789abcdef' # Olark OLARK_SITE_ID = '1234-567-89-0123' # Optimizely OPTIMIZELY_ACCOUNT_NUMBER = '1234567' # Performable PERFORMABLE_API_KEY = '123abc' # Rating@Mail.ru RATING_MAILRU_COUNTER_ID = '1234567' ``` -------------------------------- ### Configure Additional Yandex.Metrica Tracking Options Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/yandex_metrica.rst This snippet illustrates how to set various optional constants in `settings.py` to customize Yandex.Metrica's tracking behavior. These options include enabling Webvisor, hash tracking, disabling indexing, and dispatching e-commerce data. ```python YANDEX_METRICA_WEBVISOR = True YANDEX_METRICA_TRACKHASH = True YANDEX_METRICA_NOINDEX = True YANDEX_METRICA_ECOMMERCE = True ``` -------------------------------- ### Override User Identity in django-analytical Template (Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/features.rst This example shows how to set the 'analytical_identity' context variable directly within a Django template using the 'with' tag. This provides a way to customize the identity passed to analytics services on a per-template basis. ```django {% with analytical_identity=request.user.uuid|default:None %} {% analytical_head_top %} {% endwith %} ``` -------------------------------- ### Override User Identity in django-analytical View (Python) Source: https://github.com/jazzband/django-analytical/blob/main/docs/features.rst This code demonstrates how to manually set the 'analytical_identity' context variable within your Django view. This allows you to override the default user identification for analytics tracking, for example, by using a user's UUID. ```python context = RequestContext({'analytical_identity': user.uuid}) return some_template.render(context) ``` -------------------------------- ### Set Visitor Nickname via Template Context (Python/Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/olark.rst This example shows how to set a visitor's nickname in the Olark operator buddy list using a Django RequestContext. The 'olark_nickname' (or 'olark_identity') variable takes precedence over 'analytical_identity'. This is useful when your website identifies users. ```python from django.template import RequestContext # ... context = RequestContext({'olark_nickname': nick}) return some_template.render(context) ``` -------------------------------- ### Configure Multiple Analytics Services in Django Source: https://context7.com/jazzband/django-analytical/llms.txt Enable and configure multiple analytics services like Google Analytics, Mixpanel, Hotjar, Clicky, Crazy Egg, and Lucky Orange simultaneously. All services are managed through Django settings and rendered via template tags. Global settings like ANALYTICAL_INTERNAL_IPS and ANALYTICAL_AUTO_IDENTIFY can affect all services. ```python # settings.py INSTALLED_APPS = [ # ... other apps 'analytical', ] # Google Analytics GOOGLE_ANALYTICS_GTAG_PROPERTY_ID = 'G-XXXXXXXX' # Mixpanel MIXPANEL_API_TOKEN = '0123456789abcdef0123456789abcdef' # Hotjar HOTJAR_SITE_ID = '1234567' # Clicky CLICKY_SITE_ID = '12345678' # Crazy Egg CRAZY_EGG_ACCOUNT_NUMBER = '12345678' # Lucky Orange LUCKYORANGE_SITE_ID = '123456' # Global settings affecting all services ANALYTICAL_INTERNAL_IPS = ['127.0.0.1', '192.168.1.100'] ANALYTICAL_AUTO_IDENTIFY = True ``` -------------------------------- ### Configure Optimizely A/B Testing in Django Settings Source: https://context7.com/jazzband/django-analytical/llms.txt This Python snippet sets up Optimizely for A/B testing within Django. The OPTIMIZELY_ACCOUNT_NUMBER is required to enable experimentation features. ```python # settings.py OPTIMIZELY_ACCOUNT_NUMBER = '1234567' ``` -------------------------------- ### Configure Google Analytics (gtag.js) Source: https://context7.com/jazzband/django-analytical/llms.txt Set up Google Analytics using the gtag.js implementation by providing your property ID in Django settings. This integration supports various property ID formats and allows for optional IP filtering to exclude internal traffic. ```python # settings.py GOOGLE_ANALYTICS_GTAG_PROPERTY_ID = 'G-XXXXXXXX' # or 'UA-XXXXXX-X' # Optional: Exclude internal IP addresses from tracking GOOGLE_ANALYTICS_INTERNAL_IPS = ['192.168.1.1', '10.0.0.1'] ``` -------------------------------- ### Pass Mixpanel Identity via RequestContext Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/mixpanel.rst This Python code example shows how to pass a visitor's identity to Mixpanel using a RequestContext in Django. The 'mixpanel_identity' variable in the context will be used by the Mixpanel tag to identify the user. This is useful for tying events to specific users. ```python from django.template import RequestContext context = RequestContext({'mixpanel_identity': identity}) return some_template.render(context) ``` -------------------------------- ### Set Visitor Email using RequestContext in Django Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/snapengage.rst Demonstrates how to set the visitor's email address for SnapEngage using a Django RequestContext. This is useful when the email can be determined from the current request. ```python from django.template import RequestContext # Assuming 'email' is a variable holding the visitor's email address context = RequestContext({'snapengage_email': email}) return some_template.render(context) ``` -------------------------------- ### Track Revenue with Template Context Variables Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/spring_metrics.rst This Python snippet illustrates how to track the revenue generated from conversions using the `spring_metrics_revenue` template context variable. It also includes the `spring_metrics_convert` variable for marking the conversion event. ```python from django.template import RequestContext context = RequestContext({ 'spring_metrics_convert': 'sale', 'spring_metrics_revenue': '30.53', }) return some_template.render(context) ``` -------------------------------- ### Configure Intercom Live Chat in Django Source: https://context7.com/jazzband/django-analytical/llms.txt Set up Intercom for live chat and customer engagement by providing your INTERCOM_APP_ID. For enhanced security, enable identity verification with INTERCOM_HMAC_SECRET_KEY. Custom user data can be passed from views. ```python # settings.py INTERCOM_APP_ID = 'abc123def456' # Optional: Enable identity verification (recommended for security) INTERCOM_HMAC_SECRET_KEY = 'your-hmac-secret-key' ``` ```python # views.py - Pass custom user data to Intercom from django.shortcuts import render def account_page(request): context = { 'intercom_name': request.user.get_full_name(), 'intercom_email': request.user.email, 'intercom_user_id': str(request.user.id), 'intercom_plan': 'enterprise', 'intercom_company': request.user.profile.company_name, 'created_at': int(request.user.date_joined.timestamp()) } return render(request, 'account.html', context) ``` -------------------------------- ### Configure Hotjar Analytics in Django Source: https://context7.com/jazzband/django-analytical/llms.txt Enable Hotjar for heatmaps, session recordings, and user feedback by setting the HOTJAR_SITE_ID in your Django settings. Optionally, exclude internal traffic using HOTJAR_INTERNAL_IPS. ```python # settings.py HOTJAR_SITE_ID = '1234567' # Optional: Exclude internal traffic HOTJAR_INTERNAL_IPS = ['192.168.1.0/24'] ``` -------------------------------- ### Configure Olark Site ID (Django Settings) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/olark.rst This code snippet demonstrates how to set your Olark site ID in your Django project's settings file. The OLARK_SITE_ID is required for the Olark chat window to render correctly on your website. Obtain your site ID from your Olark account's installation page. ```python OLARK_SITE_ID = 'XXXX-XXX-XX-XXXX' ``` -------------------------------- ### Add Hotjar Template Tag to Base Template (Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/hotjar.rst This snippet shows how to load and insert the Hotjar template tag into your base HTML template. This ensures that the Hotjar tracking code is included on every page. Ensure the django-analytical package is installed and the 'analytical' app is in INSTALLED_APPS. ```django {% load hotjar %} ... {% hotjar %} ... ``` -------------------------------- ### Load Chartbeat Template Tags and Insert Tracking Code Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/chartbeat.rst This snippet demonstrates how to load the Chartbeat template tag library and insert the necessary tracking code into your HTML templates. The `chartbeat_top` tag should be placed in the head section, and `chartbeat_bottom` in the body section for accurate page load time measurement. ```django.html {% load chartbeat %} {% chartbeat_top %} ... {% chartbeat_bottom %} ``` -------------------------------- ### Pass Custom Visitor Data to Intercom via Django View Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/intercom.rst This example illustrates how to pass custom visitor data to Intercom from a Django view. By including variables like 'intercom_cart_value' in the RequestContext when rendering a template, you can enrich the data sent to Intercom for each visitor. This allows for more detailed tracking and analysis. ```python from django.template import RequestContext context = RequestContext({'intercom_cart_value': cart.total_price}) return some_template.render(context) ``` -------------------------------- ### Configure Default UserVoice Widget Key Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/uservoice.rst This Python code demonstrates how to set the default UserVoice widget key in your Django project's settings.py file. If this setting is present but empty, no widget will be shown by default. ```python USERVOICE_WIDGET_KEY = 'XXXXXXXXXXXXXXXXXXXX' ``` -------------------------------- ### Pass User Identity to UserVoice via Django Context Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/uservoice.rst This Python example shows how to manually pass user identity information to UserVoice using a Django RequestContext. It constructs a dictionary containing user traits like email and name, which can then be rendered in a template. This method is useful for explicitly sending user data when automatic detection is insufficient. ```python context = RequestContext({'uservoice_identity': {'email': user_email, 'name': username }}) return some_template.render(context) ``` -------------------------------- ### Set Custom User Identity for Google Analytics gtag.js in Django Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/google_analytics_gtag.rst This example shows how to override the default user identification for Google Analytics gtag.js. By setting the 'google_analytics_gtag_identity' context variable to a unique identifier like a user's UUID, you can avoid sending Personally Identifiable Information (PII) and comply with Google Analytics conditions. This can be done in a Django view or directly in the template. ```python context = RequestContext({'google_analytics_gtag_identity': user.uuid}) return some_template.render(context) ``` ```django {% with google_analytics_gtag_identity=request.user.uuid|default:None %} {% analytical_head_top %} {% endwith %} ``` -------------------------------- ### Load and Insert Yandex.Metrica Template Tag Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/yandex_metrica.rst This snippet shows how to load the Yandex.Metrica template tag library and insert the tag into your HTML head. This is crucial for rendering the Yandex.Metrica tracking code on your pages. Ensure this is placed in your base template for site-wide tracking. ```django.html {% load yandex_metrica %} ... {% yandex_metrica %} ... ``` -------------------------------- ### Configure Matomo Domain and Site ID Source: https://context7.com/jazzband/django-analytical/llms.txt Set the Matomo domain path and site ID in your Django settings to enable Matomo analytics. This configuration is necessary for connecting to your self-hosted Matomo instance. ```python # settings.py MATOMO_DOMAIN_PATH = 'analytics.example.com' MATOMO_SITE_ID = '4' # Optional: Disable cookies for GDPR compliance MATOMO_DISABLE_COOKIES = True ``` -------------------------------- ### Load and Insert KISSmetrics Template Tag Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_metrics.rst This snippet shows how to load the KISSmetrics template tag library and insert the tag into your HTML head. This is necessary for tracking pages with KISSmetrics. Ensure the 'analytical' app is in INSTALLED_APPS and the KISSmetrics JavaScript code is inserted at the top of the head. ```django {% load kiss_metrics %} {% kiss_metrics %} ... ``` -------------------------------- ### Context processor to track IP protocol version Source: https://github.com/jazzband/django-analytical/blob/main/docs/tutorial.rst A Python context processor that determines the visitor's IP protocol version (IPv4 or IPv6) and makes it available in the template context as 'crazy_egg_var1'. This is used for custom data segmentation in Crazy Egg. ```python def track_ip_proto(request): addr = request.META.get('HTTP_X_FORWARDED_FOR', '') if not addr: addr = request.META.get('REMOTE_ADDR', '') if ':' in addr: proto = 'ipv6' else: proto = 'ipv4' # assume IPv4 if no information return {'crazy_egg_var1': proto} ``` -------------------------------- ### Configure GoSquared Site Token in Django Settings Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/gosquared.rst This snippet demonstrates how to set the GoSquared site token in your Django project's settings.py file. The token is obtained from your GoSquared account and is necessary for the tracking code to be rendered. ```python GOSQUARED_SITE_TOKEN = 'XXX-XXXXXX-X' ``` -------------------------------- ### Configure Performable API Key in Django Settings Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/performable.rst This code demonstrates how to set the Performable API key in your Django project's settings.py file. The API key is required for the performable tag to render the necessary JavaScript code for tracking. ```python PERFORMABLE_API_KEY = 'XXXXXX' ``` -------------------------------- ### Configure Olark Texts in Django Settings Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/olark.rst Demonstrates how to set Olark chat texts site-wide based on the current language using a context processor in Django's settings.py. This allows for dynamic text changes based on the user's locale. ```python OLARK_TEXTS = { 'en': { 'welcome title': "Click for Live Help", 'chatting_title': "Live Help: Now chatting", ... }, 'nl': { 'welcome title': "Klik voor online hulp", 'chatting_title': "Online hulp: in gesprek", ... }, ... } def set_olark_texts(request): lang = request.LANGUAGE_CODE.split('-', 1)[0] texts = OLARK_TEXTS.get(lang) if texts is None: texts = OLARK_TEXTS.get('en') return dict(('olark_%s' % k, v) for k, v in texts.items()) ``` -------------------------------- ### Set KISSmetrics API Key in settings.py Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/kiss_metrics.rst Configure your KISSmetrics API key within your Django project's settings.py file. This key is essential for the KISSmetrics tag to render the tracking code correctly. If not set, tracking will not occur. ```python KISS_METRICS_API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ``` -------------------------------- ### Configure KISSmetrics Funnel Analysis in Django Settings Source: https://context7.com/jazzband/django-analytical/llms.txt This Python code configures KISSmetrics for funnel analysis and conversion tracking in Django. It requires the KISS_METRICS_API_KEY for authentication. ```python # settings.py KISS_METRICS_API_KEY = '0123456789abcdef0123456789abcdef01234567' ``` -------------------------------- ### Configure SnapEngage Widget ID Source: https://github.com/jazzband/django-analytical/blob/main/docs/install.rst Sets the unique identifier for the SnapEngage widget. This is a required parameter for integrating SnapEngage chat functionality. ```python SNAPENGAGE_WIDGET_ID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' ``` -------------------------------- ### Configure Gauges Real-Time Analytics in Django Settings Source: https://context7.com/jazzband/django-analytical/llms.txt This Python code configures Gauges for real-time web analytics in Django settings. The GAUGES_SITE_ID must be provided for the service to function. ```python # settings.py GAUGES_SITE_ID = '0123456789abcdef0123456789abcdef' ``` -------------------------------- ### Tag Conversion with Template Context Variable Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/spring_metrics.rst This Python code shows how to mark a conversion event using the `spring_metrics_convert` template context variable. This is an alternative to tagging conversion pages in Spring Metrics' site settings. ```python from django.template import RequestContext context = RequestContext({'spring_metrics_convert': 'mailinglist signup'}) return some_template.render(context) ``` -------------------------------- ### Define Clicky Global Properties in Context Processor (Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/clicky.rst This snippet illustrates how to use a context processor to set global custom properties for Clicky tracking. By adding a function to TEMPLATE_CONTEXT_PROCESSORS in settings.py, you can automatically pass variables like 'clicky_timeout' to your templates, avoiding repetitive view logic. ```python def clicky_global_properties(request): return {'clicky_timeout': 10} ``` -------------------------------- ### Set User Variables via Context Processor (Django Settings) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/crazy_egg.rst Demonstrates how to set user variables for Crazy Egg segmentation using a context processor in Django. This is useful for variables that can be computed from the HTTP request and applied across multiple views. Add the processor to TEMPLATE_CONTEXT_PROCESSORS. ```python def track_admin_role(request): if request.user.is_staff(): role = 'staff' else: role = 'visitor' return {'crazy_egg_var3': role} ``` -------------------------------- ### Set Chartbeat Domain via Django Context Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/chartbeat.rst This Python code demonstrates how to manually set the Chartbeat domain within a Django view's context. This is useful when you need to override the default domain behavior or when not using the sites framework. The `chartbeat_domain` context variable will be used by the Chartbeat tracking code. ```python from django.template import RequestContext context = RequestContext({'chartbeat_domain': 'example.com'}) return some_template.render(context) ``` -------------------------------- ### Set Heap Tracker ID in Django Settings Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/heap.rst This code snippet shows how to configure your Heap Tracker ID within your Django project's settings.py file. Ensure this ID is correctly set for tracking to function. If not provided, the tracking code will not be rendered. ```python HEAP_TRACKER_ID = 'XXXXXXXX' ``` -------------------------------- ### Load and Insert Optimizely Template Tag in Django Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/optimizely.rst This snippet demonstrates how to load the Optimizely template tag library and insert the Optimizely tag into your Django base template. This is essential for rendering the Optimizely JavaScript code on your pages for A/B testing. ```django {% load optimizely %} {% optimizely %} ... ``` -------------------------------- ### Identify Users with UserVoice in Django Context Processor Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/uservoice.rst This Python code illustrates how to identify users for UserVoice by passing their traits through a Django context processor. It attempts to extract user details like email, name, ID, and account information, returning them in a dictionary. This method allows for richer user tracking in UserVoice. ```python def identify(request): try: return {'uservoice_identity': { email: request.user.username, name: request.user.get_full_name(), id: request.user.id, type: 'vip', account: { name: 'Acme, Co.', monthly_rate: 9.99, ltv: 1495.00, plan: 'Enhanced' } } } except AttributeError: return {} ``` -------------------------------- ### Set Visitor Nickname via Context Processor (Python/Django) Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/olark.rst This Python code defines a context processor to automatically set the visitor's nickname in Olark based on the authenticated user's email. Add this processor to your TEMPLATE_CONTEXT_PROCESSORS in settings.py. If the user is not authenticated, it returns an empty dictionary. ```python def set_olark_nickname(request): try: return {'olark_nickname': request.user.email} except AttributeError: return {} ``` -------------------------------- ### Configure Mixpanel API Token Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/mixpanel.rst This snippet demonstrates how to set the Mixpanel API token in your Django project's settings.py file. The token is essential for the Mixpanel tracking code to be rendered and for events to be sent to your Mixpanel project. If not set, tracking will be disabled. ```python MIXPANEL_API_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ``` -------------------------------- ### Load and Insert Gaug.es Template Tag in Django Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/gauges.rst This snippet shows how to load the Gaug.es template tag library and insert the Gaug.es tracking tag into an HTML template. It's typically placed in the base template's head section for site-wide tracking. ```django {% load gauges %} {% gauges %} ... ``` -------------------------------- ### Track Individual Users with Matomo Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/matomo.rst This snippet demonstrates how to set the Matomo user ID for tracking individual users. It involves creating a user object and a context dictionary, setting the 'matomo_identity' to the user's identifier. This is crucial for personalized analytics. ```python request.user = User(username='BDFL', first_name='Guido', last_name='van Rossum') context = Context({ 'matomo_identity': None }) ``` -------------------------------- ### Add Chartbeat Domain Context Processor Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/chartbeat.rst This Python code defines a context processor to automatically add the `chartbeat_domain` to your Django templates. By adding this processor to `TEMPLATE_CONTEXT_PROCESSORS` in `settings.py`, you can ensure a consistent domain is sent to Chartbeat across your application. ```python def chartbeat(request): return {'chartbeat_domain': 'example.com'} ``` -------------------------------- ### Create Context Processor for Global Analytics Data in Django Source: https://context7.com/jazzband/django-analytical/llms.txt Inject analytics data into all templates automatically using a custom context processor. This allows setting variables like IP protocol version, custom dimensions, and user identity globally without modifying individual views. Ensure the context processor is added to your TEMPLATES settings. ```python # myproject/context_processors.py def analytics_data(request): data = {} # Track IP protocol version for Crazy Egg segmentation addr = request.META.get('HTTP_X_FORWARDED_FOR', '') or request.META.get('REMOTE_ADDR', '') data['crazy_egg_var1'] = 'ipv6' if ':' in addr else 'ipv4' # Set Google Analytics custom dimensions if hasattr(request, 'LANGUAGE_CODE'): data['google_analytics_custom_dimensions'] = { 'language': request.LANGUAGE_CODE } # Set user identity if authenticated if request.user.is_authenticated: data['analytical_identity'] = str(request.user.uuid) data['intercom_company'] = getattr(request.user, 'company_name', None) return data ``` ```python # settings.py TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'myproject.context_processors.analytics_data', ], }, }, ] ``` -------------------------------- ### Add Custom UserVoice Trigger Link Source: https://github.com/jazzband/django-analytical/blob/main/docs/services/uservoice.rst This HTML snippet shows how to make the UserVoice widget launch when a visitor clicks a link by adding the 'data-uv-trigger' HTML attribute. ```html Contact us ```