<!-- Carebit docs: Google Tag Manager -->

# Google Tag Manager

Carebit can load your Google Tag Manager container on the Patient Portal
booking flow, from the first booking page through to a successful
booking. When the booking is confirmed, Carebit pushes a
`booking.confirmed` event into the GTM data layer with a `booking`
object. You can use that event to send a conversion to Google Ads or
another tag.

This page is for marketing agencies and developers who manage PPC or
analytics for a Carebit clinic. You do not need a Carebit staff login
to configure GTM itself. A member of the clinic team with access to
**Settings** must paste your container ID into Carebit.

This is browser-side tracking on the Patient Portal. It is separate from
[Developer Platform webhooks](/guides/webhook-setup). Those deliver
signed JSON to your server. They do not load GTM.

## Add your container ID

1. In Google Tag Manager, copy the container ID. It looks like
   `GTM-ABCDEF`.
2. Ask a clinic administrator to sign in to Carebit and open
   **Settings & tools > Organisation settings > Patient Portal**.
3. Paste the container ID into **Google Tag Manager container ID** and
   click **Save**.

Carebit then loads the GTM snippet on these Patient Portal paths:

- `/patients/bookings/new` - the patient starts the booking. Track
  landing-page hits and any `utm_*` or `gclid` parameters on the URL
  here.
- `/patients/bookings/complete` - the booking succeeded. Carebit pushes
  `booking.confirmed` on this page.
- `/patients/bookings/:id/complete-payment` - the patient finishes
  paying for a booking that required payment.

Replace the hostname with the clinic's Patient Portal, for example
`https://example-clinic.carebit.co/patients/bookings/new`.

## The booking.confirmed event

When `/patients/bookings/complete` loads a confirmed booking, Carebit
pushes one data-layer event:

- `event` is `booking.confirmed`
- `booking` is the booking that was just created

Carebit pushes that event once per booking ID in the current page. A
refresh does not send a second conversion for the same booking.

In Google Tag Manager, create a **Custom Event** trigger whose event
name is `booking.confirmed`. Point your Google Ads conversion tag, or
any other tag, at that trigger.

You can also create Data Layer variables for fields you want to send
with the conversion, such as `booking.id`, `booking.services.0.price`,
or `booking.clinician.formatted_name`.

![The browser console showing window.dataLayer after Carebit pushes booking.confirmed](/guides/gtm-booking-confirmed-data-layer.png)

An example `booking` object is:

```json
{
  "id": "da6ed73c-63bf-4ac7-883b-a2bf5d48fa76",
  "creation_source": "patient",
  "start_time": "2025-05-12T16:45:00.000+01:00",
  "end_time": "2025-05-12T17:45:00.000+01:00",
  "status": "confirmed",
  "location": {
    "id": "3e29d297-5f56-443f-9efa-9d420eeec01a",
    "title": "The Hampshire Clinic"
  },
  "services": [
    {
      "id": "c6357daa-8778-4c83-848a-9a51901a42de",
      "title": "Initial patient consultation",
      "price": "320.0",
      "currency": "gbp"
    }
  ],
  "clinician": {
    "id": "e11acb4d-aeb2-4864-8211-922d5cd61cf8",
    "formatted_name": "Dr James Smith"
  },
  "organization": {
    "id": "00000000-0000-4000-8000-000000000001",
    "name": "Example Clinic"
  },
  "patient": {
    "id": "65905116-f474-48ce-b8cf-3d1d87ea1d21"
  },
  "is_remote": false
}
```

The `patient` object contains only the Patient ID. It does not include
the patient's name or contact details.

## Test the integration

You need a live booking-complete URL with a booking ID, patient ID, and
booking magic-link token. If you do not have a Carebit login, ask the
clinic to send you a URL for an example or test patient. Do not use a
real patient's booking.

To build the URL from Carebit:

1. Open an example patient's profile and go to the **Bookings** tab.
2. Find a confirmed booking, then click **Actions > View in Patient
   Portal**.
3. That opens a path like
   `/patients/bookings/123?patientId=456&magicLinkToken=789`, where
   `123` is the booking ID, `456` is the patient ID, and `789` is the
   magic-link token.
4. Change the path to
   `/patients/bookings/complete?id=123&patientId=456&magicLinkToken=789`
   and load it in the browser.

In the browser developer console, inspect `window.dataLayer`. You should
see `booking.confirmed` and the `booking` object. Preview your GTM
container to confirm that your conversion tag fires.

## Optional thank-you page redirect

Organisation settings can also set **Redirect patients after they
complete an online booking**. If that URL is set and GTM is configured,
Carebit waits up to two seconds for GTM tags that listen to
`booking.confirmed` to finish, then sends the patient to your thank-you
page. The redirect URL does not include booking or patient identifiers.

If the redirect URL is set and no GTM container ID is set, Carebit
redirects immediately.

## Lead forms

Lead forms can load a separate GTM container ID. That container is
independent of the Patient Portal booking container. A submitted lead
form pushes a `lead_form_submit` data-layer event.
