Skip to content

Instantly share code, notes, and snippets.

@seanberto
Last active November 15, 2022 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanberto/33d60933a6a79143dcc2add4c4db9dd4 to your computer and use it in GitHub Desktop.
Save seanberto/33d60933a6a79143dcc2add4c4db9dd4 to your computer and use it in GitHub Desktop.
An advanced attribution script that can be added to Additional Scripts in Shopify's Checkout Settings, to ensure traffic attribution for Accelerated Checkouts.
{% if first_time_accessed %}
<!-- Fueled Advanced Attribution Tracking Script -->
<script defer src="https://www.googletagmanager.com/gtag/js?id=[G_TARGET]"></script>
<script defer src="https://cdn-client.fueled.io/fueled-client-1.1.0.min.js"></script>
<script>
const fueledConfig = {
"analyticsWriteKey": "[ANALYTICS_WRITE_KEY]",
"frontendStorageUrl": "https://frontend-storage.fueled.io",
"datahubUrl": "https://datahub.fueled.io",
"settings": {
"gTarget": "[G_TARGET]"
}
};
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', fueledConfig.settings.gTarget);
window.addEventListener("fueled-ready", function () {
fueledClient.loadClient(
fueledConfig.datahubUrl,
fueledConfig.analyticsWriteKey,
fueledConfig.settings,
).then(() => fueledClient.setFrontendStorage(
fueledConfig.frontendStorageUrl,
Shopify.checkout.token,
));
});
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment