Skip to help content
RightMessage

Use Google Tag Manager's dataLayer without code

You'll target visitors, show widgets, and personalize text with the values and events your site already sends to Google Tag Manager.

Available on the Grow, Scale, and Pro plans.

Updated

View as Markdown

If your site uses Google Tag Manager (GTM) or gtag.js, it already sends useful facts to window.dataLayer: the visitor's plan, a cart value, a purchase, a form submission. RightMessage can read those facts directly. You don't need to copy them into JavaScript variables or cookies.

You can use the dataLayer in three places:

  • Conditions: segment rules, campaign audiences, widget targeting rules, and flow Yes/No conditions. Campaigns need Scale or Pro.
  • Widget triggers: open a Popup, Toaster, Bar, or Full-screen takeover when an event such as purchase fires.
  • Merge text: show a value in a phrase, widget, or flow, such as {{ datalayer.user.first_name }}.

What RightMessage reads

Your site adds facts to the dataLayer with dataLayer.push(...):

JavaScript
dataLayer.push({ user: { plan: 'pro', first_name: 'Ada' } })
dataLayer.push({ event: 'purchase', ecommerce: { value: 49, currency: 'USD' } })

RightMessage reads the dataLayer the same way GTM's Data Layer Variable does:

  • Each push is merged into one set of values. A later push for the same key replaces the earlier value. Other keys stay. After the two pushes above, user.plan is pro and ecommerce.value is 49.
  • You name a value with a dot path, such as ecommerce.value, user.plan, or ecommerce.items.0.item_id.
  • Any push with an event key is an event. gtag('event', 'sign_up', { method: 'Google' }) is an event too.

It doesn't matter whether your site pushes before or after RightMessage loads. RightMessage reads earlier pushes when it starts and watches for later ones.

Target visitors with a dataLayer value

  1. Open the condition editor for a segment, a campaign audience, a widget's Targeting rules, or a flow condition.
  2. Choose Google Tag Manager › Data layer value.
  3. Enter the dot path, for example user.plan.
  4. Choose a comparison, such as Equals, Contains, Greater than, or Is set, and enter the value.
If you'd like to target…PathComparisonValue
Paying customersuser.planEqualspro
Big cartsecommerce.valueGreater than100
Logged-in visitorsuser.idIs set

Values are read on the current page. When your site pushes a new value, RightMessage checks your segments, campaigns, and widget targeting again. Widgets that start to match then appear. A widget that's already showing stays.

Target visitors who fired an event

  1. Choose Google Tag Manager › Data layer event.

  2. Enter the event name, for example purchase, form_submit, or gtm.formSubmit.

  3. Choose Has fired or Has not fired.

  4. Choose on this page view or this session. this session also counts earlier pages the visitor opened in the same tab during this visit, once a published condition uses this session for that event.

    On a single-page app, where moving between screens doesn't load a new page, on this page view counts every event pushed since the page last loaded, because the dataLayer keeps them.

  5. Optional: after where, enter a key from the same push, such as form_id. Then enter the value it must equal, such as newsletter. Leave the value blank to require only that the key is present.

For this session, RightMessage keeps a short record in the visitor's browser of the events your conditions name, and only the keys they compare. It never stores the rest of the push.

Show a widget when an event fires

  1. Open the widget and go to Display › When it appears.
  2. Choose When a Google Tag Manager event fires.
  3. In Event name, enter the event, such as purchase.
  4. Optional: in Only when this key is set, enter a key from the same push, such as form_id. In and equals, enter the value it must have, such as newsletter.

The widget appears once, the first time a matching event is pushed on the page. A matching push from before RightMessage loaded also counts. Its Targeting rules still apply. Until you enter an event name, the widget doesn't appear. See the widget display reference for the other display settings.

Show dataLayer values in text

Use datalayer. followed by the dot path in any merge text. The data picker has examples in its Google Tag Manager dataLayer section.

Liquid
Welcome back, {{ datalayer.user.first_name | default: 'friend' }}!
{% if datalayer.ecommerce.value > 100 %}You qualify for free shipping.{% endif %}

Text uses the values pushed by the time it's shown. Add a default for visitors whose page hasn't pushed the value. The flow data and Liquid reference lists the other paths you can use.

Check it on your site

Choose Preview on your site in the dashboard. In the debugger:

  • The Liquid panel lists the values RightMessage read under Page & session, with paths starting datalayer.
  • A widget waiting for its event says "Will appear when the page pushes the purchase event to the dataLayer."
  • Conditions that use the dataLayer show whether they matched.

To test without changing your site, open your browser's developer console on your page and push a value yourself:

JavaScript
dataLayer.push({ event: 'purchase', ecommerce: { value: 120, currency: 'USD' } })

Things to know

  • RightMessage reads the array named window.dataLayer. Containers that use another dataLayer name aren't read.
  • Values aren't remembered between pages, as in GTM. Only events can be checked across a session.
  • Key matching for events compares text exactly. USD doesn't match usd.
  • RightMessage doesn't change what's in your dataLayer. GTM and your other tags keep working as before.
  • Sending RightMessage's own A/B test impressions to the dataLayer is a separate switch. See Install RightMessage with Google Tag Manager.

Still need a hand?

Tell us what you’re trying to do and where you’re getting stuck.

support@rightmessage.com