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: 2name:
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)
Type
sf plugins
to see the current versionInstall the right version by using
sf plugins install salesforce/plugin-PLUGIN_NAME@x.x.x
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]
To fix, remove these lines in networks.
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
The issue is regarding the Navigation Menu Item. To fix:
You can query the corrupted Navigation Menu Items using the following query. Open Developer Console and copy this to SOQL query:
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 / .
Useful Links
To check if metadata is supported in that version, click Metadata Coverage Report.
To automate deployment using unlocked packages, click Automate Experience Cloud Sites Deployment Using Unlocked Packages (Video) and I want to package (unlocked 2GP) a Digital Experience; what metadata do I need?.
To see references, see Salesforce Developers.
Author
Edward Wong
Last updated