Connect Maglr to Hubspot (via GTM)
To send page views from your Maglr publications to Hubspot, add two tags in Google Tag Manager (GTM): the Hubspot tracking code and a page-view tag. Hubspot then shows which pages of your publications your Hubspot contacts viewed. You need a GTM container that is connected to your domain name in Maglr, and a Hubspot account.
Connecting Google Tag Manager to your domain name
Maglr loads your GTM container through the settings of the domain name your projects are published on. Only users with the Admin role can change domain name settings. To connect it:
- In the dashboard, go to
Settings→Domain names. - Click the pencil icon next to the domain name your projects are published on.
- In the Statistics & integration section, turn on
Google Analytics or GTM. - Set
Integration typetoGoogle Tag Manager. - In
GTM code, enter your GTM container ID (for exampleGTM-XXXXXXXX). - Click
Save changes.
The GTM code applies to every project published on that domain name. Projects on another domain name need the GTM code on that domain name too. For more on statistics and GTM in Maglr, see Statistics with Maglr.
Adding the Hubspot tracking code in Google Tag Manager
The Hubspot tracking code identifies the visitors of your Maglr publications in Hubspot and records the first page they open. To add it to GTM:
- In Hubspot, copy your own Hubspot tracking code. It starts with
<!-- Start of HubSpot Embed Code -->. - In Google Tag Manager, create a new tag of the type
Custom HTML. - Paste the tracking code unchanged into the
HTMLfield. - Under
Triggering, selectAll Pages. - Save the tag.
Copy the code from your own Hubspot account. Don't write it yourself from an example: the script address in the code depends on the region of your Hubspot account, so a code written from an example may load the wrong script.

Tracking every page view in Hubspot
The Hubspot tracking code records only the first page a visitor opens in a Maglr publication. Maglr publications change pages without reloading, so you need a second Custom HTML tag in Google Tag Manager that records each next page. This tag fires on a History Change trigger, because every page change in a Maglr publication is a history change in the browser.
To add the page-view tag:
- In Google Tag Manager, create a second tag of the type
Custom HTML. - Paste the code below into the
HTMLfield. - Under
Triggering, add a trigger of the typeHistory Changethat fires on all history changes. - Save the tag.
<script>
var _hsq = window._hsq = window._hsq || [];
_hsq.push(['setPath', window.location.pathname + window.location.search]);
_hsq.push(['trackPageView']);
</script>
The code sends Hubspot the path of the page the visitor is on, so you can paste it without changes.

The screenshot shows the tag type and the History Change trigger. Use the code block above as the code to paste.
Publishing and testing the setup
Tags in Google Tag Manager only start working after you publish the GTM container. To publish and test the Hubspot tags:
- In Google Tag Manager, click
Submit. - Click
Publish. - Open the live URL of a project on the domain name that has your GTM code.
- Browse through a few pages of the publication.
Test on the project's live URL, not in a preview. Maglr doesn't load GTM in previews, so preview visits never reach Hubspot.
When the setup works, the activity of a Hubspot contact shows the pages they viewed in your publications, similar to this example:

Tracking more events in Hubspot
You can add more Hubspot tracking code through Google Tag Manager, such as custom events that track clicks inside your publication. Hubspot explains the available code in its Hubspot tracking code API documentation.
Frequently asked questions
Why don't I see any page views in Hubspot when I preview my project?
Maglr doesn't load Google Tag Manager in previews, so the Hubspot tags don't run there. Test the setup on the project's live URL, after you have published your GTM container.
Why does Hubspot show only the first page a visitor opened?
The Hubspot tracking code records only the first page a visitor opens. To record each next page of a Maglr publication, add a second Custom HTML tag in Google Tag Manager with the page-view code from Tracking every page view in Hubspot, and fire it on a History Change trigger. Then publish the GTM container again.
Do I need to add the GTM code to every domain name?
Yes, if you publish projects on more than one domain name. The GTM code is set per domain name in Maglr, under Settings → Domain names, and applies to every project published on that domain name. A project on a domain name without the GTM code doesn't load your GTM container.
Does Maglr's cookie consent stop the Hubspot tracking code?
No. Maglr's cookie consent doesn't block tags in Google Tag Manager. It reports the consent status to GTM, so if you need consent before Hubspot tracks a visitor, add that condition to the triggers of your Hubspot tags in GTM. For Maglr's consent options, see Configure cookie consent.
Updated on: 27/10/2026