The HubSpot tracking code allows you to identify visitors, track events, and track page views.
_hsq
array:
_hsq
array is processed when the tracking code is loaded, so you can push an identify
call to the array before the code loads to have the identity information pushed with the initial trackPageView
call.
trackPageView
is automatically called when the tracking code loads, so you should not push any trackPageView
calls to _hsq
before the page loads.usertoken
(stored in the visitors browser in the hubspotutk
cookie) and the email address. When the HubSpot tracking code tracks an action (such as a page view) for a visitor, it automatically associates that action with the usertoken
. When you use the Tracking Code API to identify a visitor by email address, the analytics system will tie that email to the usertoken
, allowing HubSpot to update an existing contact record or create a new one. HubSpot will validate the email address used for any process that would create or update a contact record. Analytics data (page views, original source, etc.) associated with the usertoken
will show up on the contact record.
With this in mind, you should only use the identify
method when you know the identity (i.e. the email address) of the person viewing the page. Using a placeholder email for unknown visitors will create a contact record with that placeholder email, and the visitor’s usertoken
cookie will be associated with that record, meaning that all unknown visitors would be associated with that single placeholder contact.
Keep in mind that the identify
function only sets the identities in the tracker. The identities do not get passed to HubSpot until you make a separate trackPageView
or trackEvent
call.
Please note that the HTTP API cannot be used to associate analytics data with a contact record, though you can still use the email=
parameter in the URL to associate the event with the contact with that email address (or create a new contact if the email address does not belong to an existing record).
trackEvent
function is used to track behavioral events in your HubSpot reports. Events are used to track that some action occurred, and can be tied to a contact record so that you can see if/when a contact triggered that event. While you can set up simple events in HubSpot, you can use the Events API to track more complicated processes on your website or track events that occur offline.
setPath
and trackPageView
functions to update and track the current page:
identify
- Identify a visitor by emailtrackEvent
- Track behavioral eventstrackPageView
- Track page viewssetPath
- Set path for single-page applicationsaddPrivacyConsentListener
- Check consent statusrevokeCookieConsent
- Remove consent cookiesdoNotTrack
- Prevent all tracking