Articles on: Share & analyse

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:


  1. In the dashboard, go to Settings → Domain names.
  2. Click the pencil icon next to the domain name your projects are published on.
  3. In the Statistics & integration section, turn on Google Analytics or GTM.
  4. Set Integration type to Google Tag Manager.
  5. In GTM code, enter your GTM container ID (for example GTM-XXXXXXXX).
  6. 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.


Maglr gives no support for the scripts you add through Google Tag Manager. Setting up tags in GTM requires some technical knowledge.


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:


  1. In Hubspot, copy your own Hubspot tracking code. It starts with <!-- Start of HubSpot Embed Code -->.
  2. In Google Tag Manager, create a new tag of the type Custom HTML.
  3. Paste the tracking code unchanged into the HTML field.
  4. Under Triggering, select All Pages.
  5. 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.


Image: Custom HTML Tag in Google Tag Manager


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:


  1. In Google Tag Manager, create a second tag of the type Custom HTML.
  2. Paste the code below into the HTML field.
  3. Under Triggering, add a trigger of the type History Change that fires on all history changes.
  4. 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.


Image: Custom HTML Tag in Google Tag Manager


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:


  1. In Google Tag Manager, click Submit.
  2. Click Publish.
  3. Open the live URL of a project on the domain name that has your GTM code.
  4. 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:


Image: activity data in Hubspot


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.



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