### 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 %}