Articles on: Share & analyse

Connect Maglr events with Google Tag Manager

Maglr pushes page views and visitor interactions in a publication to the Google Tag Manager (GTM) data layer. In GTM, you turn these events into variables, triggers and tags, and send them to Google Analytics 4 (GA4) or another tool. This article uses GA4 as the example; the same variables and triggers work for any tool you connect through GTM.


To set it up in GTM, you:


  • create Data Layer Variables for the Maglr information you want to use
  • create Custom Event triggers for the Maglr events you want to respond to
  • create tags that send the events to GA4
  • test the setup on your published publication


Before you start


Maglr only pushes events to a GTM container that is linked to your domain. In the settings of your domain, in the Statistics & integration section, switch on Google Analytics or GTM, set Integration type to Google Tag Manager and enter your GTM code. If you haven't done this yet, follow the steps in this article first.


Maglr events in the GTM data layer


Maglr sends each tracked action in a publication to the GTM data layer as an event. The event name is what you respond to in GTM: "if this event happens, then send this to GA4". For example, when a visitor clicks a link in a page, Maglr pushes a maglrUserEvent with the category, action and label of that click, and GTM can forward those to GA4.


Event names are case-sensitive. Use them exactly as written below.


Page events:


  • maglrPageView: sent when the first page of a publication loads. GTM's built-in page view trigger already fires on this first load, so you don't need a separate trigger for it.
  • maglrVirtualPageView: sent every time the visitor moves to another page in the publication. Maglr changes the page without reloading the browser, so this is a "virtual" page view.
  • maglrPageEvent: sent once for each page when Maglr has loaded it, including pages it preloads in the background. Most setups don't need it, because it doesn't show which pages the visitor actually saw.


Interaction events:


  • maglrUserEvent: sent when a visitor interacts with the content of a page, such as a link, video, slideshow, tab menu, accordion or stepper.
  • maglrInterfaceEvent: sent when a visitor uses the navigation around the content, such as the overview page, navigation menu, side menu or cookie banner. Form submissions also arrive as a maglrInterfaceEvent, with category Form, action Submit and the form name as label.


Consent event:


  • maglrConsentChanged: sent when cookie consent is switched on for the domain and the visitor's choice is known or changes. It carries the variable maglrCookieConsented (true or false).


Variables Maglr sends with each event


Maglr events carry information about the page they happened on. maglrUserEvent and maglrInterfaceEvent also carry the category, action and label of the interaction. maglrConsentChanged only carries maglrCookieConsented. Use the variable names exactly as written; they are case-sensitive.


Variable

What it contains

maglrCategory

The category of the interaction, for example Link, Video or Form

maglrAction

The action, for example External, Started or Submit

maglrLabel

The label, for example the URL of a clicked link or the name of a form. For most interactions with page content, Maglr adds the project ID and page ID at the end. For a link to another page in the publication, the label is the path of that page instead.

maglrValue

For interactions with page content, the ID of the project. Most other events don't include it.

maglrElementName

The name of the element the visitor interacted with, for element-level events

maglrElementID

The ID of that element, for element-level events

maglrIssueID

The ID of the project

maglrSpreadID

The ID of the current page

maglrLanguage

The language of the publication, as a locale such as nl_NL

maglrPageType

The type of page, for example publication

maglrPageStatus

The status of the page: created, started, paused or stopped

maglrReferenceTag

The reference tag of the page, only when the page has one

maglrPagePath

The path of the page, without a leading slash, for example projectname/pagename

maglrPageURL

The full URL of the page

maglrPageTitle

The title of the page

maglrProjectTitle

The title of the project

MaglrCookieConsented

true when the visitor has accepted cookies. Otherwise false: the visitor rejected cookies, hasn't chosen yet, or cookie consent isn't switched on for the domain. Note the capital M.


For example, a click on an external link in a page arrives with maglrLabel set to https://example.com :: (123|456), where 123 is the project ID and 456 is the page ID. maglrValue is then 123.


Creating Data Layer Variables in GTM


To use information from Maglr's data layer in a GTM tag, create a Data Layer Variable for each Maglr variable you need. The GA4 setup in this article uses maglrCategory, maglrAction and maglrLabel.


  1. In GTM, open your container and go to Variables.
  2. Under User-Defined Variables, click New.
  3. Choose the variable type Data Layer Variable.
  4. In Data Layer Variable Name, enter the Maglr variable name exactly, for example maglrCategory.
  5. Give the variable a name, for example maglrCategory, and click Save.


Image: Data Layer Variable in Google Tag Manager


  1. Repeat these steps for maglrAction, maglrLabel and any other Maglr variable you want to use.


Image: all Data Layer Variables to use with Maglr


Creating Custom Event triggers for Maglr events


A Custom Event trigger makes a GTM tag fire when a specific Maglr event arrives in the data layer. To send content and interface interactions to GA4, create one trigger for maglrUserEvent and one for maglrInterfaceEvent.


  1. In GTM, go to Triggers and click New.
  2. Choose the trigger type Custom Event.
  3. In Event name, enter maglrUserEvent. The name is case-sensitive.
  4. Leave the trigger on All Custom Events.
  5. Give the trigger a name and click Save.


Image: Custom Event Trigger in Google Tag Manager


  1. Repeat these steps with the event name maglrInterfaceEvent.


Sending Maglr events to Google Analytics 4


A GA4 Event tag in GTM sends a Maglr event to GA4, with the Maglr category, action and label as event parameters. You need the Data Layer Variables and Custom Event triggers for maglrUserEvent and maglrInterfaceEvent described above.


  1. In GTM, go to Tags and click New.
  2. Choose Google Analytics, then Google Analytics: GA4 Event.
  3. In Measurement ID, enter your GA4 measurement ID (it starts with G-).
  4. In Event Name, enter a name for the event in GA4, for example maglr_user_event.
  5. Under Event Parameters, add three parameters: maglr_category with value {{maglrCategory}}, maglr_action with value {{maglrAction}} and maglr_label with value {{maglrLabel}}.
  6. Under Triggering, select the Custom Event trigger you created for maglrUserEvent.
  7. Give the tag a name and click Save.
  8. Repeat these steps for a second tag with the Custom Event trigger you created for maglrInterfaceEvent, for example with the event name maglr_interface_event.


Tip: start the names of your Maglr events and parameters with maglr_, so you can tell Maglr events apart from your other events in Google Analytics.


GA4 only shows event parameters in its standard reports after you register them as custom dimensions in GA4, under Admin > Data display > Custom definitions.


Measuring page views in a Maglr publication


Maglr changes pages in a publication without reloading the browser. It changes the URL with the browser's history, which GTM sees as a History Change. To measure page views in GA4, your GTM container needs a Google tag with your GA4 measurement ID (it starts with G-). That Google tag counts these page changes as page views automatically when the GA4 enhanced measurement option "Page changes based on browser history events" is on, which it is by default.


If that option is off, use one of these methods to count each page change as a page view:


  • a GA4 Event tag with the event name page_view on a trigger of type History Change
  • a GA4 Event tag with the event name page_view on a Custom Event trigger for maglrVirtualPageView


Use only one method. If you combine enhanced measurement, a History Change trigger and a maglrVirtualPageView trigger, GA4 counts the same page view more than once.


Testing your GTM setup


GTM doesn't load on Maglr preview links, so test your tags on the published publication.


  1. In GTM, click Preview.
  2. Enter the URL of your published publication, not a Maglr preview link.
  3. Click through the publication and check in Tag Assistant that your tags fire on the Maglr events.
  4. In GA4, open the Realtime report or DebugView to see the events arrive.
  5. When everything works, click Submit in GTM to publish your container.


Frequently asked questions


Which Maglr event do form submissions use?


Form submissions in a Maglr publication arrive in the GTM data layer as a maglrInterfaceEvent, not a maglrUserEvent. The category is Form, the action is Submit and the label is the name of the form. To track form submissions, use a Custom Event trigger for maglrInterfaceEvent.



GTM isn't loaded on Maglr preview links, so no events reach GTM or Google Analytics from a preview. Test your setup on the published publication: in GTM, click Preview and enter the URL of the live publication.


Does Maglr push events when a visitor hasn't accepted cookies?


Yes. Maglr loads your GTM container and pushes its events to the GTM data layer whether or not the visitor has accepted cookies. Maglr's cookie consent doesn't block GTM or the tags in it. To fire tags only with consent, add a condition to your triggers that MaglrCookieConsented equals true, or respond to the maglrConsentChanged event, which carries maglrCookieConsented (true or false). MaglrCookieConsented is true only after the visitor accepts cookies.


Do Maglr's own statistics still work when I use GTM?


Yes. Google Tag Manager works alongside Maglr's standard statistics. Connecting GTM doesn't change the Activate standard Maglr statistics switch in your domain's Statistics & integration settings.

Updated on: 20/10/2026