Shopify: Fix Sandbox URLs issue in GA4

Google Analytics BCS 2 days ago 41 Views 0 Comments

Table of Contents

Update time: June 5, 2025

 

Issue

In the GA4 report, the URL is garbled, the structure is like /wpm@10e09e41w77fb031apd6c28ceam532d5d9a/custom/web-pixel-118849878@4/sandbox/modern/page-name

 

Reason

This is because GA4 is installed through Shopify Custom Pixel, which runs in Sandbox, so there will be a URL with the above structure.

 

Solution

Instead of using default tracking, use custom events to actively send clean URLs.

First, turn off default page tracking, because Custom Pixel is installed in Sandbox, and the URL in Sandbox is irregular, such as the structure /wpm@10e09e41w77fb031apd6c28ceam532d5d9a/custom/web-pixel-118849878@4/sandbox/modern/page-name, so the default page tracking cannot be used, but the Google Tags needs to be loaded. You need to set send_page_view to false so that the default page tracking will not be sent.

In GTM, click「Tags」——「New」——「Choose a tag type to begin setup…」——「Google Analytics」——「Google Tag」, name it “Disable Default PageView”, and then make the following settings:

 

 

Second, use custom events to send actual page tracking. The code is as follows. Copy it into Shopify’s Custom Pixel:

analytics.subscribe('page_viewed', (event) => {
  window.dataLayer.push({
   'event': 'page_viewed',
   'page_location': event.context.window.location.href,
   'page_title': event.context.document.title,
  });
});

In GTM, click「Variable」——「New」——「Choose a variable type to begin setup…」——「Data Layer Variable」, name it “dlv_page_location”, and then make the following settings:

Similarly, create the data layer variable dlv_page_title.

 

In GTM, click「Trigger」——「New」——「Choose a trigger type to begin setup…」——「Custom Event」, name it “page_viewed”, and then make the following settings:

 

In GTM, click「Tags」——「New」——「Choose a tag type to begin setup…」——「Google Analytics」——「Google Analytics: GA4 Event」, name it “GA4-Event-PageView”, and then make the following settings:

In this way, the URLs in the GA4 report are all clean URLs, excluding Sandbox ones.


If you don't understand, You can leave a comment below.
Like (0)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website