Last active
June 3, 2025 02:34
-
-
Save leohackin/621757b8b2928094e114eab48aeea86b to your computer and use it in GitHub Desktop.
Shopify Customer Event to get Checkout Errors and send to GA4 using gtag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const script = document.createElement('script'); | |
| script.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX'); | |
| script.setAttribute('async', ''); | |
| document.head.appendChild(script); | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'G-XXXXXXX'); | |
| analytics.subscribe('alert_displayed', (event) => { | |
| const { target, type, message, value } = event.data.alert; | |
| gtag('event', 'checkout_error', { | |
| error_name: event.name, | |
| error_message: message, | |
| error_target: target, | |
| error_type: type, | |
| error_value: value, | |
| error_event_name: event.name, | |
| error_event_type: event.type | |
| }); | |
| console.log("Evento GA4 enviado via GTAG"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment