Google Analytics 4 Page Types in Data 360

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 

TaskPermission
Configure Web SDK IntegrationData 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.

Configuration Object Field Specifications 

FieldTypeRequiredExampleDescription
pageTypestringYescartDefines the current page; see Salesforce Page Types.
contextualAttributesobjectNo{...}Provides extra metadata related to the specific page context.
sendEventbooleanNotrueSends a page_view event to Data 360; see GA4 Event Mapping.

Provide Configuration to the Data Layer Method 

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 logic
7  pageType: "product",
8
9  // Object containing metadata specific to this page view
10  contextualAttributes: {
11    // 1. Static Attribute: A simple hardcoded string.
12    pageTypeAttr: "product-pageTypeAttr",
13
14    // 2. DOM Selector Resolver: Automatically scrapes the text content
15    // of the first <h2> tag found on the page.
16    pageTypeAttr2: SalesforceInteractions.resolvers.fromSelector("h2"),
17
18    // 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    ),
25
26    // 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");
32
33        // 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 50ms
44    ),
45  },
46
47  // Boolean flag to trigger an immediate 'page_view' event to the server
48  sendEvent: true,
49});
50</script>

Configure a Google Tag Manager (GTM) Tag 

In Google Tag Manager:

  1. Go to your workspace and create a tag.
  2. Under Tag configuration, select Custom HTML.
  3. Paste your sfWebInteractionsDataLayer.push() method into the code editor. Enclose the method in a <script> tag.
  4. 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 TypeDescription
homeThe website’s homepage
blogThe blog’s main index or homepage
blog_detailA specific blog post or article page
searchThe initial search entry page
search_resultsThe page showing search query results
registerThe user account registration page
sign_inThe user login page
accountThe user’s account overview or profile page
error_pageA landing page for errors (for example, 404 Not Found)

Commerce Page Types 

You can define these page types for a commerce website.

Page TypeDescription
product_detailA product detail page
brandA brand detail page
departmentA department overview page
categoryA category page, sometimes referred to as a product list page
cartThe shopping cart
checkoutThe checkout pages
order_confirmationThe order confirmation page

B2B Page Types 

You can define these page types for a B2B website.

Page TypeDescription
productA specific product offering
solutionA group of offerings, high-level capability, or industry
articleA details page for articles (for example, White Papers or Technical Specs)
eventA details page for events (for example, Webinars or Conferences)
learningA 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>
4
5<!-- 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    });
13
14    var f = d.getElementsByTagName(s)[0],
15      j = d.createElement(s),
16      dl = l != 'dataLayer' ? '&l=' + l : '';
17
18    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>
4
5<!-- From Google Tag (gtag.js) documentation -->
6<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
7
8<script>
9  window.dataLayer = window.dataLayer || [];
10
11  function gtag() {
12    dataLayer.push(arguments)
13  };
14
15  gtag('js', new Date());
16  gtag('config', 'TAG_ID');
17</script>
18<!-- End Google Tag (gtag.js) -->