Install conversion tracking with Google Tag Manager

Google Tag Manager (GTM) lets you manage Rebrandly conversion tracking entirely within your GTM container. This guide walks through loading the Rebrandly script, tracking page views, sending conversion events, and testing before you go live.

The standard <script> tag with data-api-key placed in your site's <head> does not work when pasted into GTM. Use the loader script in Step 1 instead.

Before you begin

  • Conversion tracking is enabled in your Rebrandly workspace
  • You have your conversion tracking API key
  • GTM is already installed on your site

Important: Rebrandly tracks only visitors who arrive through a Rebrandly link. Those links append a rbly_click_id parameter to the URL. To test locally, open your site through a Rebrandly link or manually add rbly_click_id=test123 to the URL (use ? if there are no existing query parameters, otherwise use &).

Step 1: Load the Rebrandly script

  1. In GTM, go to Tags → New → Custom HTML.
  2. Set the trigger to Initialization - All Pages.
  3. Paste the following, replacing YOUR_API_KEY with your key:
<script>
  (function () {
    var s = document.createElement('script');
    s.src = 'https://cdn.rebrandly.com/analytics/sdk/v1/rbly.min.js';
    s.onload = function () {
      window.rbly.init({ apiKey: 'YOUR_API_KEY' });
    };
    document.head.appendChild(s);
  })();
</script>

Rebrandly now loads on every page, including single-page applications.

Step 2: Page views (automatic)

No additional setup is needed. Once the script from Step 1 is loaded, Rebrandly tracks page views automatically on first load and on every client-side navigation when an rbly_click_id is present.

Step 3: Track conversions

A conversion is an action you want to measure: a purchase, sign-up, or similar event.

Push the event to the data layer

Add this to your site where the action completes:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'purchase',
  conversion: {
    label: 'purchase',
    value: 49.00,
    currency: 'USD',
    properties: { orderId: 'ORDER-123' }
  }
});

For non-monetary conversions (such as a sign-up), change the event name and conversion.label to match (for example, signup), and set value: null and currency: null.

Configure GTM to forward the event

Add three items in GTM:

VariableVariables → New → Data Layer Variable

  • Name: conversion data
  • Data Layer Variable Name: conversion (exact match)

TriggerTriggers → New → Custom Event

  • Event name: ^(purchase|signup)$
  • Enable Use regex matching to cover multiple event types with one trigger

TagTags → New → Custom HTML, using the trigger above:

<script>
  var c = {{conversion data}};
  if (window.rbly && c) {
    window.rbly.convert(c.label, c.value, c.currency, c.properties || null);
  }
  // Note: if the SDK hasn't finished loading when this tag fires, the conversion
  // will be silently dropped. This can happen on fast page redirects. For
  // production use, consider adding retry logic.
</script>

The SDK suppresses duplicate events with the same signature within the deduplication window (default 10 seconds). Don’t rely on deduplication to clean up GTM configuration mistakes — ensure only one GTM tag fires per user action, since different tag setups can produce different event signatures and be counted separately.

Optional — Track conversions via button click

If you can modify your button's HTML but want to avoid adding JavaScript or data layer code to your site, you can fire a conversion directly from a button click in GTM.

Add these attributes to the button in your HTML:

<button data-rbly-buy
        data-rbly-label="purchase"
        data-rbly-value="49.00"
        data-rbly-currency="USD">
  Buy now
</button>

Then in GTM:

  1. Go to Variables → Configure and enable Click Element.
  2. Create a trigger: Triggers → NewAll Elements (under the Click group) → Some Clicks → condition: Click Element matches CSS selector [data-rbly-buy], [data-rbly-buy] *
  3. Create a tag: Tags → New → Custom HTML, using that trigger:
<script>
  var el = {{Click Element}};
  el = el && el.closest ? el.closest('[data-rbly-buy]') : el;
  if (el && window.rbly) {
    var v = parseFloat(el.getAttribute('data-rbly-value'));
    window.rbly.convert(
      el.getAttribute('data-rbly-label') || 'purchase',
      isNaN(v) ? null : v,
      el.getAttribute('data-rbly-currency') || null
    );
  }
  // Note: if the SDK hasn't finished loading when this tag fires, the conversion
  // will be silently dropped. For production use, consider adding retry logic.
</script>

Use either the data layer method (Step 3) or the button-click method for the same conversion event, not both. Using both counts the same conversion twice.

Step 4: Test and publish

🚧

No sandbox or test mode

Conversion tracking has no sandbox or test mode. Events fired during testing are recorded as real data. Use clearly identifiable test values (for example, orderId: 'TEST-001') or test conversion labels (for example, test_purchase or dev_signup) so they can be filtered out later.

  1. Click Preview in GTM and open your site through a Rebrandly link.
  2. Complete a test purchase or sign-up.
  3. In Tag Assistant, confirm your conversion tag appears under Tags Fired.
  4. Click Submit / Publish to go live.

Troubleshooting

ProblemWhat to check
Nothing is trackedConfirm you opened the site through a Rebrandly link, or add ?rbly_click_id=test123 to the URL.
Conversion tag doesn't fireIn the Custom Event trigger, Event name must match your event (for example, purchase), not a URL. Use regex matching must be enabled.
Tag fires but no conversion is recordedIn the data layer variable, Data Layer Variable Name must be exactly conversion.
Conversions are counted twiceRemove either the data layer tag or the button-click tag — not both — for the same action.
Works in preview but not liveClick Submit / Publish in GTM to deploy the container.