Skip to content

Instantly share code, notes, and snippets.

@svaustin66
Last active April 23, 2024 02:01
Show Gist options
  • Save svaustin66/e4298d9c28902e91a6ad31969178ae2b to your computer and use it in GitHub Desktop.
Save svaustin66/e4298d9c28902e91a6ad31969178ae2b to your computer and use it in GitHub Desktop.
<!-- Tracking Klaviyo Sign-ups in GA4 -->
<script>
window.addEventListener("klaviyoForms", function(e) {
if (e.detail.type == 'open' || e.detail.type == 'embedOpen') {
gtag('event', 'klaviyo_form_open', {'form': 'Klaviyo form', 'form_id': e.detail.formId});
}
if (e.detail.type == 'submit') {
gtag('event', 'klaviyo_form_submit', {'form': 'Klaviyo form', 'form_id': e.detail.formId});
}
if (e.detail.type == 'stepSubmit') {
gtag('event', 'klaviyo_form_step_submit', {'form': 'Klaviyo form', 'step_name': e.detail.metaData.$step_name});
}
if (e.detail.type == 'redirectedToUrl') {
gtag('event', 'klaviyo_form_url_redirect', {'form': 'Klaviyo form', 'form_id': e.detail.formId});
}
if (e.detail.type == 'close') {
gtag('event', 'klaviyo_form_close', {'form': 'Klaviyo form', 'form_id': e.detail.formId});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment