Here is a native solution from Google on how to install Google Analytics 4 in Shopify.
Requirements
- Access to Google Analytics (admin)
- Access to Shopify > Settings > Customer Event
Get Your GA4 Code
First lets find your Google Analytics Measurement ID by going to:
- Google Analytics
- Cog Icon (admin)
- Under Data collection and modification, choose Data Streams
- Click on your data stream
- Now you can view and copy your measurement id

Now go to Shopify > Settings > Customer Events
And click on Add custom pixel
You can give it any pixel name, but I will call it Google Analytics. Now click on Add pixel.
Get the code:https://merchantcodex.com/google-analytics-4-code-for-shopify-pixels/
The code below is developed by Google, now replace the tagId value with your measurement id.
Now paste your code in the custom even code section.
Set your permission to Analytics
Set your data sale to Data collected does not qualify as data sale