Send event to Google Analytics 4
This hook enables you to send event data from your Shopify store directly to Google Analytics 4 using the Measurement Protocol. Use it to track purchases and other customer interactions without additional client-side code.
Prerequisites
- Google Analytics 4 API Secret
- Google Analytics 4 Measurement ID
- A Shopify store with Cloudhooks installed
Configuration
1) Set up trigger
Create a new hook in the Cloudhooks dashboard with "An order is created" as your trigger event.
2) Configure authentication
Update these variables in the hook code with your Google Analytics credentials:
const API_SECRET = '[Your GA4 API secret]';
const MEASUREMENT_ID = '[Your GA4 measurement id]';
3) Implement the hook
Copy and paste this code into your hook editor:
You can send recommended events and custom events to Google Analytics via the Measurement Protocol .
The following example sends a purchase event to Google Analytics (the hook expects an order payload):
Testing
Test your hook using Cloudhooks' test payload feature before activating it in production. Use a sample order payload from your store.
Notes
- It typically takes 24-48 hours for events to appear in Google Analytics reports.
- This example demonstrates a purchase event, but you can modify it to send any recommended events or custom events.
Additional Resources
- Google Analytics 4 Measurement Protocol documentation
- More Cloudhooks examples on our GitHub Gist page
- For detailed setup instructions, visit our complete integration guide