This guide walks you through configuring DataLayer Guard in the Code-Cube.io portal so it can validate your dataLayer events using page scenarios: automated browser flows that replicate real user journeys. New to DataLayer Guard? Start with DataLayer Guard introduction.
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 templates to validate
- Test, activate, and verify the scenario
⏰ Estimated time: 15 - 20 minutes per scenario
🔧 Requirements: Access to the Code-Cube.io portal with DataLayer Guard enabled, and a list of the pages and user flows you want to monitor
- Step 1 – Configure general settings
- Step 2 – Create a page scenario
- Step 3 – Configure cookie acceptance and login (optional)
- 3.1 Cookie acceptance
- 3.2 Login
- Step 4 – Add scenario steps
- Step 5 – Define the dataLayer template for each collect step
- Step 6 – Test, activate, and verify
- 6.1 Test
- 6.2 Activate
- 6.3 Verify
- Troubleshooting
- Next steps
Step 1 – Configure general settings
Before building any scenario, tell DataLayer Guard which domains to monitor, which time zone to report in, and how often to 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 runs 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 are 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 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.
- On the DataLayer Guard configuration page, click Monitoring via page scenarios
- Click + Add scenario
- Enter a 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 is matched
- Page type: which part of the URL the match applies to
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 only needs to include the value somewhere |
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 (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 URL with a query string.
Step 3 – Configure cookie acceptance and login (optional)
Most 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.
3.1 Cookie acceptance
- Inside the scenario, turn Cookies acceptance 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 more click steps if your banner needs multiple interactions
3.2 Login
- Turn Login required on
- Add the steps in order, for example:
Go to page: the login page URLFill input field: username selector and valueFill input field: password selector and valueClick on element: submit button selector
⚠️ Important: Use a dedicated test account for login scenarios. Never enter real user credentials, because scenarios are stored in the portal configuration.
💡 Tip: If several scenarios share the same cookie or login flow, build it once as aReusable components and reference it from each scenario.
Step 4 – Add scenario steps
Steps describe the user journey. DataLayer Guard runs them 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 step
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 field |
Select dropdown menu option | Selects an option from a dropdown ( <select> element) |
Select date range | Picks dates in a calendar widget |
Wait until element appear | Pauses until a selector becomes visible (use before unreliable interactions) |
Check cookie value | Checks 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 |
Settings per step:
- Delay: seconds to wait after the step completes (for animations or content that loads later)
- Optional: when on, a failure of this step does not stop the scenario
- Wait for page load: pauses after the action until the new page has loaded
- Opens new page: continues in the new tab or page opened by the action
Example: "Add to cart" flow
Go to page→https://www.example.com/Click on element→ selector for the product linkWait until element appear→ selector for the "Add to cart" buttonClick on element→ selector for the "Add to cart" buttonCollect dataLayer object→ event name:add_to_cart
🧠 Insight: UseCollect dataLayer before navigationwhen the page navigates away right after pushing an event (e.g.purchaseon order completion). The regularCollect dataLayer objectonly sees events that stay on the current page.
💡 Tip: If a step fails now and then, 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 define what the event should look like: which keys must be present, and what type of value each key holds.
- In the step row, click the Edit dataLayer template icon
- The DataLayer Template panel opens on the right
- For each property, set:
- Key: the dataLayer key (e.g.
event,ecommerce.value) - Type:
string,number,boolean,array, orobject - Required: turn on if the key must always be present
- Exact match: turn on if the value must equal a specific value (otherwise only the type is validated)
- For ecommerce events, click Insert default template and pick a GA4 preset (
add_to_cart,begin_checkout,view_item,view_item_list,view_cart,remove_from_cart) to prefill the structure - Click Save to close the panel
💡 Tip: Start with the default GA4 template and remove what your site doesn't use. It's faster than building from scratch and avoids typos.
⚠️ Important: Only mark a field as Required if it is present every time the event fires. Marking optional fields as required causes false alerts.
Step 6 – Test, activate, and verify
New scenarios start paused. Activate a scenario only when you're confident its steps are correct.
6.1 Test
Run the scenario in the Scenario Tester to watch every step live and fix any failing step before you activate it.
6.2 Activate
- In the scenarios table, click the ▶ Play icon next to your scenario, or set Status to Active in the scenario panel
- Click Save changes at the top of the panel
6.3 Verify
- Open DataLayer Guard > Dashboard
- Wait until the next scheduled run (see 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
Problem | Likely cause | Fix |
Scenario fails on the very first step | The starting URL's domain isn't in Company domains | Add the domain in General settings |
Cookie banner step doesn't dismiss the banner | The selector changed, or the 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 | The event fires after navigation, or the event name doesn't match | Switch to Collect dataLayer before navigation, and check the event value |
Random validation errors on a field | The field is marked Required but is only sometimes present | Make the field optional in the template |
Scenario runs but no data in the dashboard | The scenario is still paused | Set the status to Active and save |
Still stuck? Email support@code-cube.io.
Next steps
Reusable components: build shared steps, such as cookie or login flows, once
Scenario Tester: test your scenarios live before they go live
Notifications & alerts: choose where and how you receive alerts