mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Add HubSpot integration
This commit has not been tested.
This commit is contained in:
parent
a984d58ca2
commit
3d411e31d0
5 changed files with 144 additions and 1 deletions
|
|
@ -7,7 +7,8 @@ into a Django_ project. Currently supported services:
|
|||
* `Chartbeat`_ -- traffic analysis
|
||||
* `Clicky`_ -- traffic analysis
|
||||
* `Crazy Egg`_ -- visual click tracking
|
||||
* `Google Analytics`_ traffic analysis
|
||||
* `Google Analytics`_ -- traffic analysis
|
||||
* `HubSpot`_ -- inbound marketing
|
||||
* `KISSinsights`_ -- feedback surveys
|
||||
* `KISSmetrics`_ -- funnel analysis
|
||||
* `Mixpanel`_ -- event tracking
|
||||
|
|
|
|||
88
analytical/hubspot/__init__.py
Normal file
88
analytical/hubspot/__init__.py
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
"""
|
||||
============================
|
||||
HubSpot -- inbound marketing
|
||||
============================
|
||||
|
||||
HubSpot_ helps you get found by customers. It provides tools for
|
||||
content creation, convertion and marketing analysis. HubSpot uses
|
||||
tracking on your website to measure effect of your marketing efforts.
|
||||
|
||||
.. _HubSpot: http://www.hubspot.com/
|
||||
|
||||
|
||||
.. hubspot-installation:
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
You only need to do perform these steps if you are not using the
|
||||
generic :ttag:`analytical.*` tags. If you are, skip to
|
||||
:ref:`hubspot-configuration`.
|
||||
|
||||
In order to use the template tag, you need to add
|
||||
:mod:`analytical.hubspot` to the installed applications list in the
|
||||
project :file:`settings.py` file::
|
||||
|
||||
INSTALLED_APPS = [
|
||||
...
|
||||
'analytical.hubspot',
|
||||
...
|
||||
]
|
||||
|
||||
The HubSpot tracking code is inserted into templates using a template
|
||||
tag. Load the :mod:`hubspot` template tag library and insert the
|
||||
:ttag:`hubspot` tag. Because every page that you want to track must
|
||||
have the tag, it is useful to add it to your base template. Insert
|
||||
the tag at the bottom of the HTML body::
|
||||
|
||||
{% load hubspot %}
|
||||
...
|
||||
{% hubspot %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
.. _hubspot-configuration:
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
Before you can use the HubSpot integration, you must first set your
|
||||
portal ID and domain.
|
||||
|
||||
|
||||
.. _hubspot-portal-id:
|
||||
|
||||
Setting the portal ID and domain
|
||||
--------------------------------
|
||||
|
||||
Your HubSpot account has its own portal ID and primary websit, and the
|
||||
:ttag:`hubspot` tag will include them in the rendered Javascript code.
|
||||
You can find the portal ID and domain by going to the *Domains* tab in
|
||||
your HubSpot account. The domain you need to use is listed as *Primary
|
||||
Domain* on that page, and the portal ID can be found in the footer. Set
|
||||
:const:`HUBSPOT_PORTAL_ID` and :const:`HUBSPOT_DOMAIN` in the
|
||||
project :file:`settings.py` file::
|
||||
|
||||
HUBSPOT_PORTAL_ID = 'XXXX'
|
||||
HUBSPOT_DOMAIN = 'XXXXXXXX.web101.hubspot.com'
|
||||
|
||||
If you do not set the portal ID and domain, the tracking code will not
|
||||
be rendered.
|
||||
|
||||
|
||||
.. _hubspot-internal-ips:
|
||||
|
||||
Internal IP addresses
|
||||
---------------------
|
||||
|
||||
Usually you do not want to track clicks from your development or
|
||||
internal IP addresses. By default, if the tags detect that the client
|
||||
comes from any address in the :const:`INTERNAL_IPS` setting, the
|
||||
tracking code is commented out. See :const:`ANALYTICAL_INTERNAL_IPS`
|
||||
for important information about detecting the visitor IP address.
|
||||
"""
|
||||
|
||||
hubspot_service = {
|
||||
'body_bottom': 'analytical.hubspot.templatetags.hupspot.HubSpotNode',
|
||||
}
|
||||
0
analytical/hubspot/templatetags/__init__.py
Normal file
0
analytical/hubspot/templatetags/__init__.py
Normal file
53
analytical/hubspot/templatetags/hubspot.py
Normal file
53
analytical/hubspot/templatetags/hubspot.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"""
|
||||
HubSpot template tags.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from django.template import Library, Node, TemplateSyntaxError
|
||||
|
||||
from analytical.utils import get_required_setting, is_internal_ip, disable_html
|
||||
|
||||
|
||||
PORTAL_ID_RE = re.compile(r'^\d+$')
|
||||
DOMAIN_RE = re.compile(r'^[\w.-]+$')
|
||||
TRACKING_CODE = """
|
||||
<script type="text/javascript" language="javascript">
|
||||
var hs_portalid = %(portal_id)s;
|
||||
var hs_salog_version = "2.00";
|
||||
var hs_ppa = "%(domain)s";
|
||||
document.write(unescape("%3Cscript src='" + document.location.protocol + "//" + hs_ppa + "/salog.js.aspx' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
"""
|
||||
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.tag
|
||||
def hubspot(parser, token):
|
||||
"""
|
||||
HubSpot tracking template tag.
|
||||
|
||||
Renders Javascript code to track page visits. You must supply
|
||||
your portal ID (as a string) in the ``HUBSPOT_PORTAL_ID`` setting,
|
||||
and the website domain in ``HUBSPOT_DOMAIN``.
|
||||
"""
|
||||
bits = token.split_contents()
|
||||
if len(bits) > 1:
|
||||
raise TemplateSyntaxError("'%s' takes no arguments" % bits[0])
|
||||
return HubSpotNode()
|
||||
|
||||
class HubSpotNode(Node):
|
||||
def __init__(self):
|
||||
self.site_id = get_required_setting('HUPSPOT_PORTAL_ID',
|
||||
PORTAL_ID_RE, "must be a (string containing a) number")
|
||||
self.domain = get_required_setting('HUPSPOT_DOMAIN',
|
||||
DOMAIN_RE, "must be an internet domain name")
|
||||
|
||||
def render(self, context):
|
||||
html = TRACKING_CODE % {'portal_id': self.portal_id,
|
||||
'domain': self.domain}
|
||||
if is_internal_ip(context):
|
||||
html = disable_html(html, 'HubSpot')
|
||||
return html
|
||||
|
|
@ -16,6 +16,7 @@ DEFAULT_SERVICES = [
|
|||
'analytical.clicky.clicky_service',
|
||||
'analytical.crazy_egg.crazy_egg_service',
|
||||
'analytical.google_analytics.google_analytics_service',
|
||||
'analytical.hubspot.hubspot_service',
|
||||
'analytical.kiss_insights.KissInsightsService',
|
||||
'analytical.kiss_metrics.KissMetricsService',
|
||||
'analytical.mixpanel.MixpanelService',
|
||||
|
|
|
|||
Loading…
Reference in a new issue