How to add Hubspot tracking code to WordPress without plugin

Last edited:
July 16, 2023
Reading time:
3 mins
Topic:
Hubspot

/

Blog

/

Marketing

/

How to add Hubspot tracki...

đź’ˇWe may earn a commision if you subscribe to a service from a link on this page.

As a WordPress user, you might be familiar with the importance of tracking code implementation for analytics and marketing purposes. HubSpot, a popular customer relationship management (CRM) platform, offers powerful tracking capabilities. While there are plugins available to integrate HubSpot with WordPress, in this article, we will explore three alternative methods to add the HubSpot tracking code without using a plugin. These methods provide flexibility and control over the tracking implementation, allowing you to optimize your website’s performance and gather valuable data.

Option 1: Adding the HubSpot Tracking Code in Child Theme with a Hook

One (and probably the best) way to add the HubSpot tracking code to your WordPress site is by utilizing a child theme. A child theme allows you to make modifications to your site’s code without altering the parent theme directly. To implement the HubSpot tracking code using this method, follow these steps:

  1. Create a child theme: If you haven’t already, create a child theme by duplicating your current theme’s directory and creating a style.css file with necessary header information.
  2. Edit the child theme’s functions.php file: Open the functions.php file of your child theme and add the following code snippet:
<?php
function add_hubspot_tracking_code() {
?>
<!-- Paste your HubSpot tracking code here -->
<?php
}
add_action('wp_head', 'add_hubspot_tracking_code');
  1. Save and activate the child theme: Save the functions.php file and activate the child theme in your WordPress dashboard.

Option 2: Adding the Tracking Code to the header.php of the Parent Theme

Alternatively, you can add the HubSpot tracking code directly to the header.php file of your parent theme. Follow these steps:

  1. Access the header.php file: Log in to your WordPress dashboard, go to Appearance > Theme Editor, and select the header.php file.
  2. Locate the </head> tag: Scroll through the code until you find the </head> closing tag.
  3. Paste the HubSpot tracking code: Copy and paste your HubSpot tracking code just before the </head> tag.
  4. Save the changes: Click on the “Update File” button to save the modifications.

Option 3: Implementing HubSpot Tracking Code via Google Tag Manager

An alternative approach is to use Google Tag Manager (GTM) to implement the HubSpot tracking code. GTM simplifies the process of managing various tracking codes on your WordPress site. To implement the HubSpot tracking code through GTM, follow these steps:

  1. Set up a Google Tag Manager account: If you haven’t already, create a Google Tag Manager account and set up a container for your website.
  2. Get your HubSpot tracking code: Log in to your HubSpot account and navigate to Settings > Tracking Code. Copy the provided tracking code.
  3. Add the GTM container code to your WordPress site: Insert the GTM container code in the header.php file of your WordPress theme, just after the opening <body> tag.
  4. Set up a new GTM tag for HubSpot tracking: Inside your GTM account, create a new tag and select the custom HTML tag type. Paste your HubSpot tracking code into the HTML field.
  5. Configure the trigger: Set the trigger to fire on all pages of your website.
  6. Publish the changes: Save and publish your changes in GTM.

Begin your Hubspot journey!

By following these three methods, you can add the HubSpot tracking code to your WordPress site without relying on a plugin. Whether you choose to utilize a child theme with a hook for wp_header, add the code to the header.php file of your parent theme, or implement it through Google Tag Manager, remember to test the implementation and ensure that the tracking code is functioning correctly. Taking advantage of HubSpot’s tracking capabilities will provide valuable insights into your website’s performance, user behavior, and ultimately help you make informed marketing decisions.