diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index d8a269e..905ec5f 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,7 @@
+Version 0.17.2
+--------------
+* Update HubSpot code (Craig Bruce)
+
Version 0.17.1
--------------
* Fix typo in Intercom.io support (Steven Skoczen)
diff --git a/analytical/templatetags/hubspot.py b/analytical/templatetags/hubspot.py
index 0d64177..57c9a62 100644
--- a/analytical/templatetags/hubspot.py
+++ b/analytical/templatetags/hubspot.py
@@ -12,44 +12,42 @@ from analytical.utils import is_internal_ip, disable_html, get_required_setting
PORTAL_ID_RE = re.compile(r'^\d+$')
-DOMAIN_RE = re.compile(r'^[\w.-]+$')
TRACKING_CODE = """
-
+
+
+
"""
-
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``.
+ your portal ID (as a string) in the ``HUBSPOT_PORTAL_ID`` setting.
"""
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.portal_id = get_required_setting('HUBSPOT_PORTAL_ID',
- PORTAL_ID_RE, "must be a (string containing a) number")
- self.domain = get_required_setting('HUBSPOT_DOMAIN',
- DOMAIN_RE, "must be an internet domain name")
+ PORTAL_ID_RE, "must be a (string containing a) number")
def render(self, context):
- html = TRACKING_CODE % {'portal_id': self.portal_id,
- 'domain': self.domain}
+ html = TRACKING_CODE % {'portal_id': self.portal_id}
if is_internal_ip(context, 'HUBSPOT'):
html = disable_html(html, 'HubSpot')
return html
diff --git a/analytical/tests/test_tag_hubspot.py b/analytical/tests/test_tag_hubspot.py
index 043999e..c2630d3 100644
--- a/analytical/tests/test_tag_hubspot.py
+++ b/analytical/tests/test_tag_hubspot.py
@@ -10,7 +10,7 @@ from analytical.tests.utils import TagTestCase, override_settings, SETTING_DELET
from analytical.utils import AnalyticalException
-@override_settings(HUBSPOT_PORTAL_ID='1234', HUBSPOT_DOMAIN='example.com')
+@override_settings(HUBSPOT_PORTAL_ID='1234')
class HubSpotTagTestCase(TagTestCase):
"""
Tests for the ``hubspot`` template tag.
@@ -18,13 +18,13 @@ class HubSpotTagTestCase(TagTestCase):
def test_tag(self):
r = self.render_tag('hubspot', 'hubspot')
- self.assertTrue('var hs_portalid = 1234;' in r, r)
- self.assertTrue('var hs_ppa = "example.com";' in r, r)
+ self.assertTrue("n.id=i;n.src='//js.hs-analytics.net/analytics/'+(Math.ceil(new Date()/r)*r)+'/1234.js';"
+ in r, r)
def test_node(self):
r = HubSpotNode().render(Context())
- self.assertTrue('var hs_portalid = 1234;' in r, r)
- self.assertTrue('var hs_ppa = "example.com";' in r, r)
+ self.assertTrue("n.id=i;n.src='//js.hs-analytics.net/analytics/'+(Math.ceil(new Date()/r)*r)+'/1234.js';"
+ in r, r)
@override_settings(HUBSPOT_PORTAL_ID=SETTING_DELETED)
def test_no_portal_id(self):
@@ -34,20 +34,11 @@ class HubSpotTagTestCase(TagTestCase):
def test_wrong_portal_id(self):
self.assertRaises(AnalyticalException, HubSpotNode)
- @override_settings(HUBSPOT_DOMAIN=SETTING_DELETED)
- def test_no_domain(self):
- self.assertRaises(AnalyticalException, HubSpotNode)
-
- @override_settings(HUBSPOT_DOMAIN='wrong domain')
- def test_wrong_domain(self):
- self.assertRaises(AnalyticalException, HubSpotNode)
-
@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
def test_render_internal_ip(self):
req = HttpRequest()
req.META['REMOTE_ADDR'] = '1.1.1.1'
context = Context({'request': req})
r = HubSpotNode().render(context)
- self.assertTrue(r.startswith(
- ''), r)
diff --git a/docs/services/hubspot.rst b/docs/services/hubspot.rst
index 5a51c1c..cc3daa9 100644
--- a/docs/services/hubspot.rst
+++ b/docs/services/hubspot.rst
@@ -3,7 +3,7 @@ HubSpot -- inbound marketing
============================
HubSpot_ helps you get found by customers. It provides tools for
-content creation, convertion and marketing analysis. HubSpot uses
+content creation, conversion and marketing analysis. HubSpot uses
tracking on your website to measure effect of your marketing efforts.
.. _HubSpot: http://www.hubspot.com/
@@ -43,29 +43,28 @@ Configuration
=============
Before you can use the HubSpot integration, you must first set your
-portal ID and domain.
+portal ID, also known as your Hub ID.
.. _hubspot-portal-id:
-Setting the portal ID and domain
---------------------------------
+Setting the portal ID
+---------------------
-Your HubSpot account has its own portal ID and primary domain name, 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::
+Your HubSpot account has its own portal ID, the :ttag:`hubspot` tag
+will include them in the rendered JavaScript code. You can find the
+portal ID by accessing your dashboard. Alternatively, read this
+`Quick Answer page `_.
+Set :const:`HUBSPOT_PORTAL_ID` 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.
+If you do not set the portal ID, the tracking code will not be rendered.
+.. deprecated:: 0.17.2
+ `HUBSPOT_DOMAIN` is no longer required.
+
.. _hubspot-internal-ips:
Internal IP addresses