Experience Cloud

Enabling Google Analytics for Single Page Application

Accurate page view tracking in Google Analytics relies on proper setup and configuration. If not implemented correctly, Google Analytics may only record the initial page a user lands on, failing to track subsequent pages viewed during their navigation of the website. This can lead to incomplete data and a lack of visibility into the user's full journey across the site.

Step by step

To enable proper page view in Google Analytics from Salesforce Experience Cloud, make sure the following is done:

  • in Setup - All Sites - Builder

    • in Settings - Advanced, Google Analytics must be EMPTY.

    • in Settings - Head Markup

      • there is a Google Tag Manager added

      • <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXXXX');</script>

      • there is NO gtag('config', 'G-XXXXXXXXXX');

      • there is NO <script> that load Google Analytics

  • in Google Tag Manager

    • Variables

      • name: dlv - pageTitle, Data Layer Variable Name: pageTitle, version: 2

      • name: dlv - pageUrl, Data Layer Variable Name: pageUrl, version: 2

    • Triggers

      • name: Custom - virtualPageView, Event name: virtualPageView, All Custom Events

    • Tags

      • there is a Google Tag: Google Tag - G-XXXXXXXXXX

        • Tag Type: Google Tag, Tag ID: G-XXXXXXXXXX, Firing Triggers: Initialization - All Pages

        • Configuration Settings - Configuration Parameter: send_page_view, value: false

      • there is a google analytics: GA4 Event

        • insert the measurement ID G-XXXXXXXXXX

        • event name: page_view

        • event parameters

          • event parameter: page_location , value: {{dlv - pageUrl}}

          • event parameter: page_title, value: {{dlv - pageTitle}}

        • Triggering

          • Firing Triggers: Custom - virtualPageView

  • To test if everything works fine

    • Go to Chrome Extension Google Tag Assistant

    • Pick a website

    • Check the following is true (on first page load, and on changing article page)

      • there is a virtualPageView

      • there is NO other Google Analytics hit (such as history change, initialization)

Notes

  • Google Analytics must be loaded via HTML (without page_view) first although virtualPageView has been added. Without this setup, the Search Console will not record Organic Google Search query and thus missing data.

  • Google Analytics 4 (GA4) is newer than Universal Analytics (UA). UA is deprecated.

Troubleshooting

Warning: @salesforce/XX (x.x.x) differs from the version specified by sf (x.x.x)

  1. Type sf plugins to see the current version

  2. Install the right version by using sf plugins install salesforce/plugin-PLUGIN_NAME@x.x.x

  3. Make sure it install the right version by typing sf plugins again.

if the name in sf plugins is packaging, the name is @salesforce/plugin-packaging@x.x.x

Required fields are missing: [ParentId]

Error (1): Encountered errors installing the package! Installation errors: 
1) (YOUR_SITE_1) Required fields are missing: [ParentId], Details: YOUR_SITE_1: Required fields are missing: [ParentId]
2) (YOUR_SITE_2) Required fields are missing: [ParentId], Details: YOUR_SITE_2: Required fields are missing: [ParentId]
3) (YOUR_SITE_3) Required fields are missing: [ParentId], Details: YOUR_SITE_3: Required fields are missing: [ParentId]

To fix, remove these lines in networks.

<networkMemberGroups>
  <profile>Admin</profile>
</networkMemberGroups>

Deletion of a custom web address during metadata deployment from sandbox to production in Salesforce Experience Cloud

After deploying Experience Cloud Site with the Metadata API from sandbox to production in Salesforce, the custom web address gets deleted automatically, rendering it inaccessible.

Solution 1: We asked Salesforce engineer during learnexperiencecloud.com webinar. They mentioned that one solution is to have two .site-meta.xml files. When deploying to scratch org, do not use <customWebAddress> , but when deploying to prod, add <customWebAddress> so you will not lose example.com website.

Solution 2: The other hot fix is you have to manually added a custom URL by navigating to /lightning/setup/DomainNames in Salesforce setup and then creating a new custom URL with the domain www.example.com, path '/', and site YOUR_SITE_1. However, this solution temporarily brings down the website for about a minute.

An error has occurred while processing your request

An error has occurred while processing your request.
The salesforce.com support team has been notified of the problem.
If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support.
Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information.
We apologize for the inconvenience. Thank you again for your patience and assistance. And thanks for using salesforce.com! Error ID:

The issue is regarding the Navigation Menu Item. To fix:

  1. You can query the corrupted Navigation Menu Items using the following query. Open Developer Console and copy this to SOQL query:

SELECT DraftRowId,Id,Label,NavigationLinkSetId,NavigationLinkSet.NetworkId,ParentId,Status,Target,Type FROM NavigationMenuItem WHERE Status = 'Live' AND DraftRowId = null
  1. Click Delete Row on all shown results. Try the above step and try to publish the site again.

Do not rename Digital Experiences Sites in Digital Experiences - All Sites in Aura Framework. There is a very specific filename in experiences. For example, in experiences, there is a file named experiences/YOUR_SITE_1/config/yourSite.json . If you rename the site, somehow this yourSite.json file will not be renamed, hence causing error during deployment to Sandbox and/or Production. To fix, change existing site to Unused, then create a new Site with same name, and same urlPathPrefix / .

Author

Edward Wong

Last updated