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
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 touser_id, name itDLV - user_idand Save.Create the Custom Event trigger for login
Go to Triggers → New and choose Custom Event. In Event name typelogin, matching the pushed string exactly, so the trigger fires when someone logs in.Set user_id on your GA4 config
Open your GA4 base tag (the Google tag). Under Configuration settings (or shared settings) add a field nameduser_idwith value{{DLV - user_id}}. Now every GA4 hit after login carries the ID, which is what stitches sessions across devices.Fire a GA4 Event tag on login
Create a GA4 Event tag with Event Nameloginand fire it on yourlogintrigger, so the login itself is recorded. For practice you can substitute a Custom HTML tag namedCustom HTML - Testwith<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.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
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