Use the Data 360 Website Connector and Google Analytics 4 (GA4) to automatically track real-time user engagement by Page Type.
Available in:
Data Cloud, Marketing Cloud Personalization
Required Permissions
Task
Permission
Configure Web SDK Integration
Data Cloud Admin OR Marketing Cloud Personalization Salesforce admin
Overview
Use the Page Type feature with the Salesforce Web SDK to capture page-specific metadata via Google Analytics 4 (GA4) and Google Tag Manager (GTM). By pushing a pageType object and contextualAttributes to a custom data layer called sfWebInteractionsDataLayer, the Salesforce Web SDK’s GA4 module automatically identifies and tracks the context of a user’s site navigation.
Use these key capabilities of the feature to:
Standardized Context Mapping: Categorize diverse URL structures into unified page types.
Seamless GA4/GTM Interoperability: Leverage your existing Google Tag Manager logic to push page type data.
Single-Page Application Support: Support Multi-Page Applications (MPA) and Single-Page Applications (SPA) by listening for a data layer object push.
To push to the data layer, call sfWebInteractionsDataLayer.push() with a page type object. You call sfWebInteractionsDataLayer.push() when an event invokes a trigger (such as a page navigation event). Add the sfWebInteractionsDataLayer.push() code to GTM with a custom HTML tag that specifies the appropriate trigger.
Configure Page Types
Configure GTM to push page type and contextual attribute data to the Salesforce Web SDK. Create a GTM script that pushes a configuration object to the sfWebInteractionsDataLayer.
Provide the configuration as an argument to the sfWebInteractionsDataLayer.push() method. Enclose this method inside a <script> tag. For example:
1<script>2/**3 * Pushes a page-view object to the sfWebInteractionsDataLayer.4 */5sfWebInteractionsDataLayer.push({6 // Defines the category of the current page for mapping logic7 pageType: "product",89 // Object containing metadata specific to this page view10 contextualAttributes: {11 // 1. Static Attribute: A simple hardcoded string.12 pageTypeAttr: "product-pageTypeAttr",1314 // 2. DOM Selector Resolver: Automatically scrapes the text content15 // of the first <h2> tag found on the page.16 pageTypeAttr2: SalesforceInteractions.resolvers.fromSelector("h2"),1718 // 3. Simple Resolver: Uses a function to return a value.19 // .bind() ensures the function executes within the SDK's resolver context.20 pageTypeAttr3: SalesforceInteractions.util.resolveWhenTrue.bind(21 function(){22 return "product-pageTypeAttr2";23},24),2526 // 4. Asynchronous/Conditional Resolver:27 // This waiting function waits for a specific condition to be met before returning data.28 pageTypeAttrAsync: SalesforceInteractions.util.resolveWhenTrue.bind(29 function(){30 // Retrieves the standard Google Tag Manager dataLayer array.31 var events = SalesforceInteractions.getValueFromNestedObject("window.dataLayer");3233 // Condition: Only return 'true' once the dataLayer has more than three events.34 // (Useful for waiting until third-party tags or specific events have loaded.)35 if(events && events.length> 3){36 return true;37}else{38 return false;39}40},41 undefined, // Context (defaults to window)42 1000, // Timeout: Stop trying after 1000ms (1 second)43 50, // Interval: Check the condition every 50ms44),45},4647 // Boolean flag to trigger an immediate 'page_view' event to the server48 sendEvent: true,49});50</script>
Configure a Google Tag Manager (GTM) Tag
In Google Tag Manager:
Go to your workspace and create a tag.
Under Tag configuration, select Custom HTML.
Paste your sfWebInteractionsDataLayer.push() method into the code editor. Enclose the method in a <script> tag.
Configure one or more triggers to push this tag on your page. Use History Change for Single-Page Application triggers.
Page Types
Page Types establish what pages on a website and what data on those pages you want Data 360 to track. You can apply a single pageType configuration to multiple pages on your website.
Common Page Types
Map page types depending on your business vertical, the objective of your website, and the type of content your website serves.
General Page Types
You can define these general page types on any website.
Page Type
Description
home
The website’s homepage
blog
The blog’s main index or homepage
blog_detail
A specific blog post or article page
search
The initial search entry page
search_results
The page showing search query results
register
The user account registration page
sign_in
The user login page
account
The user’s account overview or profile page
error_page
A landing page for errors (for example, 404 Not Found)
Commerce Page Types
You can define these page types for a commerce website.
Page Type
Description
product_detail
A product detail page
brand
A brand detail page
department
A department overview page
category
A category page, sometimes referred to as a product list page
cart
The shopping cart
checkout
The checkout pages
order_confirmation
The order confirmation page
B2B Page Types
You can define these page types for a B2B website.
Page Type
Description
product
A specific product offering
solution
A group of offerings, high-level capability, or industry
article
A details page for articles (for example, White Papers or Technical Specs)
event
A details page for events (for example, Webinars or Conferences)
learning
A details page for learning content (for example, Classes, Playbooks, Forums, or Documentation)
Troubleshooting
If you encounter errors, define sfWebInteractionsDataLayer before initializing Google Tag Manager. For example:
1<script>2 sfWebInteractionsDataLayer = sfWebInteractionsDataLayer || [];3</script>45<!-- From Google Tag Manager documentation -->6<script>7(function(w, d, s, l, i){8 w[l]= w[l]||[];9 w[l].push({10 'gtm.start': new Date().getTime(),11 event: 'gtm.js'12});1314 var f = d.getElementsByTagName(s)[0],15 j = d.createElement(s),16 dl = l != 'dataLayer' ? '&l=' + l : '';1718 j.async = true;19 j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;20 f.parentNode.insertBefore(j, f);21})(window, document, 'script', 'dataLayer', 'GTM-XXXXXX');22</script>23<!-- End Google Tag Manager -->
For standard Google Tag implementations, define sfWebInteractionsDataLayer before initializing the Google Tag. For example:
1<script>2 sfWebInteractionsDataLayer = sfWebInteractionsDataLayer || [];3</script>45<!-- From Google Tag(gtag.js)documentation -->6<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>78<script>9 window.dataLayer = window.dataLayer || [];1011 function gtag(){12 dataLayer.push(arguments)13};1415 gtag('js', new Date());16 gtag('config', 'TAG_ID');17</script>18<!-- End Google Tag(gtag.js) -->