Welcome to CodeCrew Infotech

shape shape
Shape Shape Shape Shape

Google Analytics 4 with Shopify: A Quick Guide Part - 2

 Note: Click here to check our blog on Google Analytics 4 with Shopify: A Quick Guide Part 1


Google Analytics 4 Event


What is an event in Google Analytics 4?

An event allows you to measure a specific interaction or occurrence on your website or app, For example, you can use an event to measure when someone loads a page, clicks a link, or completes a purchase, or to measure system behavior, such as when an app crashes or an impression is served.

Meanwhile, in GA4, events are used to send a wide range of data to your reports. 

What types of events are available in Google Analytics 4?

There are four different types of events:

1. Automatically collected events 

2. Enhanced measurement events 

3. Recommended events 

4. Custom events


1. Automatically collected events: 

Automatically collected events are tracked by default in Google Analytics 4.

These events provide basic information about how users interact with your website or app, such as the pages they visit, the actions they take, and the time they spend on your site.

Here, are some of the automatically collected events in Google Analytics 4:

page_view: Tracked when a page is viewed.

first_visit: Tracked when a user visits the site for the first time.

session_start: Tracked at the beginning of each session.


2. Enhanced Measurement events:

One of the main areas where GA4 needs development is enhanced measurement events. By default, these events from Google Analytics 4 will be gathered.

You can track interactions like file downloads, outbound link clicks, embedded video plays, scrolls, and more. Even though these integrated GA4 events ought to be enabled by default, it's a good idea to confirm.

Go to Admin > Data Streams > Choose the web data stream to locate enhanced measurement events. You should notice Enhanced Measurement when a window opens.

There will be a list of seven improved measurement events that you may click to switch on or off. Then select "Save."

Page views: When a new page loads on the screen, this causes the page_view event to be generated and fired.

Scrolls: This creates the scroll event, which is triggered when a user scrolls through a page 90% of the way.

Outbound clicks: This creates the click event that is triggered by every click on an external link that leaves the domain

Site search: Every time a user utilizes your site's search function and is shown a page with search results, the view_search_results event is triggered.

Formal exchanges: When a visitor fills out a form for the first time on your website, the form_start event is triggered. When a visitor submits a form, the form_submit event occurs.

Video engagement: This event tracks video starts, progress, and completions of all embedded YouTube videos on the site. video engagement event names it generates are video_start, video_progress, and video_complete.

File downloads: If the file_download event is enabled, it will start anytime a file is downloaded from your website.


3. Recommended events:

These events let you measure additional features and behavior and generate more useful reports in Google Analytics 4. Because these events require additional context to be meaningful, they are not sent automatically. 

Ex. E-commerce events like add_to_cart, begin_checkout, Login, Sign_up, Search, View_item and purchase are all recommended events. 


4. Custom events:

A custom event is an event that you define so you can collect information about an interaction that's important to your business.

Custom events don't show up in most standard reports so you need to set up custom reports or explorations for meaningful analysis.


How to Create a Custom Event

Create new custom events with the admin section of your GA4 property

Click the bottom left Admin button, then click Property Settings> Data Display > Events.

Next, click “Create event.”


Next, click “Create.”

Now, first, select your custom event name. This is the name that will show up in your GA4 reports when your event fires. 

Now, define the requirements for your event. To keep track of "Thank You Page" visits, you'll need two prerequisites. The first condition limits your event to only fire when the event_name equals page_view.

The second condition is when the page location contains the URL of your thank you page. You can see the page_location event parameter contains “/thank-you.” 

Click the check box to “Copy parameters from the source event” to keep the same event parameters from a standard page_view event and pass them to your new custom event.


How to track GA4 events using custom GA4 code in Shopify

Shopify uses the gtag.js library for Google Analytics tracking. To implement the gtag code for Google Analytics in your Shopify store, follow these steps:

In the Installation instructions, you will get two options to install your Google tag. To connect Google Analytics to the Shopify store, you need to choose the “Install manually” option.

Now, copy this Google Analytics tracking code and go to your Shopify store.

Go to your development store and click on the online store under the sales channels selection.

Click on three dots in your current theme and select Edit Code.

In the “Layout” folder, find the `theme.liquid` file and make sure there are no Google tracking tags already added to the code.

If you don’t find any existing tracking code or file, paste the Google Analytics 4 tracking code either immediately after the <head> tag or just before the closing </head> tag. Click “Save

For example, If you want to track specific events, like remove a product from the cart page, you can add gtag event tracking code where needed.



  id="CartDrawer-Remove-{{ item.index | plus: 1 }}"

  data-index="{{ item.index | plus: 1 }}" >

  <button type="button"

  class="button button--tertiary cart-remove-button"

  aria-label="{{ 'sections.cart.remove_title' | t: title: item.title }}"

  data-variant-id="{{ item.variant.id }}"

  onclick="trackCartRemoveEvent('{{ item.variant.id }}')"  >

  {% render 'icon-remove' %}




JavaScript Code:


    function trackCartRemoveEvent(variantId) {

      // Send custom GA4 event

      gtag('event', 'cart_remove_click', {

      'event_category': 'Cart Interaction',

      'event_label': 'Remove Button Clicked',

      'variant_id': variantId,

      // Add additional parameters if needed





Go to your development store and click on the online store under the sales channels selection.

Click on three dots in your current theme and select Edit Code.

In the “Assets” folder, create one JS file (For example gtag.js) and paste the above JavaScript code.

Now go to your theme.liquid file and import your just created js file in the <head>.


GA4 Reports                               

A range of reports from Google Analytics 4 (GA4) give you information on user behavior, engagement, and performance on your website or app. The following are some important reports in GA4.

Real-time Report: gives current information on user activity, such as the number of active users, events, and conversions that are taking place.

Google Analytics presents data in standard reports by default. You’ll find those reports organized by following the different phases of a common customer lifecycle: acquisition, engagement, monetization, and retention.


1. Acquisition Reports:

You can learn more about how people found your website and where they were previously browsing from the acquisition reports. You can use this information to determine which traffic sources will help you achieve your company goal


user acquisition

In Google Analytics 4 (GA4), "user acquisition" refers to the process of bringing new users or visitors to your app or website and figuring out which routes and sources led them there. GA4 offers a suite of analytics and reports to assist companies in evaluating and improving their user acquisition tactics. The following are important facets of GA4 user acquisition.

GA4 categorizes user acquisition into different channels, including:

Organic Search: Users who find your site through search engines like Google.

Direct: Users who directly type your website URL into their browser.

Referral: Users who come from external websites linking to your site.

Social: Users who arrive from social media platforms.

Email: Users who come from email marketing campaigns.

Paid Search: Users who click on paid advertisements.

Display: Users who visit through display ads.

Other Advertising: Users acquired through other advertising channels.


Traffic acquisition 

Traffic acquisition refers to the process of attracting and gaining visitors (traffic) to a website or digital platform. It is a fundamental aspect of online marketing and web analytics, involving various strategies and channels to drive users to a specific website or app. The goal of traffic acquisition is to increase the visibility and reach of a digital property, ultimately leading to user engagement, conversions, or other desired actions.


2. Engagement Reports:

The Engagement overview report is a pre-made overview report that summarizes your engagement data. The report can help you compare key engagement metrics over time, understand which pages and screens people are visiting, and identify the features they're interacting with.

Events reports in GA4 help you understand user interactions with specific elements on your website or app. You can track custom events, such as button clicks, form submissions, or video views.

Conversions reports focus on the outcomes you want to track, such as completed transactions, sign-ups, or other significant user actions.

Pages and screens reports give you information about the performance of specific pages or screens on your website or app.

Landing page reports show you which pages users land on when they first visit your website. This is valuable for understanding entry points and user behavior.

To use the conversion report you must decide which events are the main objectives of your business and which specific user actions generate a direct benefit. Those core events can be easily marked as conversions 

Once an event has been marked as a conversion, you can assign a value to it to accurately track the total revenue generated on your website or app.


3. Monetization  Reports:

The monetization reports can show you the revenue you generate from the items, ads, and subscriptions on your website or app.

eCommerce Purchases – The revenue you generate from the items you sell in your online store.

In-app purchases – The revenue from in-app purchases and subscriptions.


4. Retention Reports

Retention reports will help you understand how engaged users are with your business. You can find out how many users return to your website, the average lifetime of your customers, and even calculate lifetime value.