Don't have one? Create one ↗
← All courses

Lesson 3 of 4

Login & User_Id

① Connect your GTM container

Paste your container ID to load it into this page. It only ever runs here.

Advanced: use a specific environment

A user_id is your own stable identifier for a logged-in person, and it is what lets GA4 stitch a single user together across phone, laptop and return visits instead of counting them as separate people. You set it on GA4 once a user is known, and from then on their activity rolls up to one profile.

The button below pushes a login event along with a user_id of u_8842. Your job is to fire a GA4 Event tag on login and to feed that user_id into GA4 so the session stitches. Send the ID only, never PII like an email address.

Goal

Fire a tag on login and set a captured user_id on GA4 so sessions stitch across devices.

Build it in GTM

  1. Capture the user_id as a Data Layer Variable

    The page pushes { event: "login", method, user_id }. In Variables, under User-Defined Variables, click New, choose Data Layer Variable, set the Data Layer Variable Name to user_id, name it DLV - user_id and Save.
  2. Create the Custom Event trigger for login

    Go to Triggers → New and choose Custom Event. In Event name type login, matching the pushed string exactly, so the trigger fires when someone logs in.
  3. Set user_id on your GA4 config

    Open your GA4 base tag (the Google tag). Under Configuration settings (or shared settings) add a field named user_id with value {{DLV - user_id}}. Now every GA4 hit after login carries the ID, which is what stitches sessions across devices.
  4. Fire a GA4 Event tag on login

    Create a GA4 Event tag with Event Name login and fire it on your login trigger, so the login itself is recorded. For practice you can substitute a Custom HTML tag named Custom HTML - Test with <script></script>, but the GA4 Event tag is the real-site choice.

Debug in Tag Assistant

Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.

  1. In your GTM, click Preview.
  2. Paste the live URL above and click Connect.
  3. Interact with the live page and watch your tag fire in Tag Assistant.

What you should expect to see

Click Log in on the live page. In Tag Assistant a login event appears in the left rail, your tag shows under Tags Fired, and the GA4 hit carries user_id set to u_8842.

Verify your container

Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.

Drop your container .json here

or browse · checked in your browser, nothing is uploaded

0 of 4 lessons complete