This guide walks you through configuring DataLayer Guard in the Code Cube portal so it can validate your dataLayer events using page scenarios, automated browser flows that replicate real user journeys.
What will you do?
- Configure your general DataLayer Guard settings
- Create a scenario and define its starting point
- Add steps that simulate the user journey (cookies, login, navigation, clicks)
- Define the dataLayer event templates to validate
- Activate the scenario and verify it runs correctly
⏰ Estimated time: 15–20 minutes per scenario 🔧 Requirements: Access to the Code Cube portal with DataLayer Guard enabled, and a list of the pages and user flows you want to monitor
🧱 Step 1: Configure General settings
Before building any scenario, set the basics that DataLayer Guard needs to know about your website: which domains it should monitor, what time zone to report in and how often it should run.
- In the portal, go to Configuration > DataLayer Guard
- Open the General settings panel
- Fill in the following:
- Company domains: every domain DataLayer Guard should monitor (e.g.
example.com,shop.example.com) - Time zone: the time zone used for scheduled runs and reporting
- Check frequency: how often DataLayer Guard should run your scenarios
- Click Save changes
⚠️ Important: Add every domain you plan to use as a starting URL in your scenarios. Scenarios that start on a domain not listed here will be blocked.
💡 Tip: You can paste a full URL (e.g.https://www.example.com/), the portal automatically stripshttps://,www., and trailing slashes.
▶️ Step 2: Create a new page scenario
A page scenario is one user journey you want DataLayer Guard to replicate. Start with a single, well-defined flow (e.g. "Homepage → product → add to cart") before building broader ones.
- From the DataLayer Guard configuration page, click Monitoring via page scenarios
- Click + Add scenario
- Fill in the Scenario name, use a descriptive label, e.g.
Add to cart — running shoes - Define the Starting point of the scenario:
- Starting URL: the page where the scenario begins
- Match type: how the URL should be matched
- Page type: which part of the URL the match applies to
Match-type options:
Match type | When to use |
exact matches | The URL must be identical to the value you provide |
matches regex | Use a regular expression for flexible patterns (e.g. localized URLs) |
contains | The URL just needs to include the value somewhere |
Page-type options:
Page type | Matched against |
hostname | The domain only (e.g. www.example.com) |
page url | The full URL including protocol, host, path, and query |
page path | Only the path portion (e.g. /products/shoes) |
🧠 Insight: The starting point determines where the headless browser begins the scenario. Keep it as stable as possible, prefer a hostname or short path over a long query-string URL.
🍪 Step 3: Configure cookie acceptance and login (optional)
Most production websites show a cookie banner before the user can reach the dataLayer events you care about. Configure these blocks once per scenario so the rest of your steps run on a clean session.
3a. Cookie acceptance
- Inside the scenario, toggle Cookies acceptance to On
- Click Add step and configure the click that dismisses your cookie banner:
- Action type:
Click on element - Element selector: a CSS selector for the "Accept all" button (e.g.
#cookie-accept) - Add additional click steps if your banner requires multiple interactions
3b. Login
- Toggle Login required to On(Optional)
- Add steps in order, e.g.:
Go to pagethe login page URLFill input fieldusername selector + valueFill input fieldpassword selector + valueClick on elementsubmit button selector
⚠️ Important: Use a dedicated test account for login scenarios. Never enter production user credentials, scenarios are stored in the portal configuration.
🧩 Step 4: Add scenario steps
The steps section is where you describe the user journey. DataLayer Guard executes each step in order. Use collect steps to tell DataLayer Guard which dataLayer events to capture and validate.
- Inside the scenario, scroll to Steps
- Click + Add step and choose an Action type for each one
💡 Tip: If multiple scenarios share the same cookie or login flow, build it once as a Reusable component (from the configuration page) and reference it from each scenario.
Available step types:
Action type | What it does |
Go to page | Navigates the browser to a URL |
Click on element | Clicks the element matching the CSS selector |
Click on random element from list | Picks one element at random, useful for product listings |
Fill input field | Types a value into an input |
Select dropdown menu option | Selects an option from a <select> element |
Select date range | Picks dates in a calendar widget |
Wait until element appear | Pauses until a selector becomes visible (use before flaky interactions) |
Check cookie value | Asserts that a cookie has the expected value |
Collect dataLayer object | Captures and validates a dataLayer event by name |
Collect dataLayer before navigation | Same as above, but captures the event right before the browser navigates away |
Per-step settings:
- Delay: seconds to wait after the step completes (use for animations or async loads)
- Optional: when on, a failure of this step does not interrupt the scenario
- Wait for page load: pauses after the action until the new page has loaded
- Opens new page: switches execution to the new tab/page opened by the action
Example step sequence, "Add to cart" flow:
Go to page→https://www.example.com/Click on element→ selector for the product linkWait until element appear→ selector for "Add to cart" buttonClick on element→ selector for the "Add to cart" buttonCollect dataLayer object→ event name:add_to_cart
🧠 Insight:Collect dataLayer before navigationis the right choice when the page navigates away immediately after pushing an event (e.g.purchaseon order completion). The regularCollect dataLayer objectonly sees events that remain on the current page.
❓ Troubleshooting: If a step fails intermittently, add a Wait until element appear step before it, or increase the Delay on the previous step.📑 Step 5: Define the dataLayer template for each Collect step
For every Collect dataLayer object (or Collect dataLayer before navigation) step, you tell DataLayer Guard what the event should look like. The template defines which keys must be present and what type of value each key should hold.
- In the step row, click the Edit dataLayer template icon
- The DataLayer Template drawer opens on the right
- For each property:
- Key: the dataLayer key (e.g.
event,ecommerce.value) - Type:
string,number,boolean,array, orobject - Required: toggle on if the key must always be present
- Exact match: toggle on if the value must equal a specific value (otherwise only the type is validated)
- For ecommerce events, click Insert default template and pick from the GA4 presets (
add_to_cart,begin_checkout,view_item,view_item_list,view_cart,remove_from_cart) to prefill the structure - Click Save to close the template drawer
💡 Tip: Start with the default GA4 template and trim what your site doesn't use. It's faster than building from scratch and reduces typos.
⚠️ Important: Only mark a field as Required if it must be present on every firing of the event. Marking optional fields as required will produce false-positive alerts.
🚀 Step 6: Activate and verify
A scenario is created in paused state by default. Activate it only after you're confident the steps are correct.
Activate
- Save the scenario (the Save changes button at the top of the drawer becomes active when you have unsaved edits)
- In the scenarios table, click the ▶ Play icon next to your scenario, or toggle Status to Active in the scenario drawer
- Save changes
Verify
- Open DataLayer Guard > Dashboard
- Wait until the next scheduled run (see your Check frequency in General settings)
- Confirm the scenario shows the events you defined under Monitored events
- Open the run details and check that each event was collected and validated as expected
❓ Troubleshooting table:
Symptom | Likely cause | Fix |
Scenario fails on the very first step | Starting URL domain isn't in Company domains | Add the domain in General settings |
Cookie banner step doesn't dismiss | Selector changed, or banner loads after a delay | Update the CSS selector, or add a Wait until element appear step before the click |
Collect dataLayer step finds no event | Event fires after navigation, or event name doesn't match | Switch to Collect dataLayer before navigation, and verify the event value |
Random validation errors on a field | Field is marked Required but is only sometimes present | Set the field to optional in the template |
Scenario runs but no data in dashboard | Scenario is still paused | Set status to Active and save |