DataSag guides · Updated 27 October 2026

Track custom events on Shopify storefront themes

Use data-datasag-goal for a click goal, or call window.datasag.track after a completed action. Choose a stable event name and distinguish a click from a successful conversion. This guide applies to Shopify storefront themes.

Start with the Shopify storefront themes installation

Back up or duplicate the theme first. Add the tracker to layout/theme.liquid before </head>, using the public key for the storefront project. Save the theme and test the published storefront. This is a theme integration, not a Shopify app installation.

The theme does not control every checkout or customer account document. A storefront pageview does not prove a completed order. Do not claim this snippet measures checkout pages or purchase revenue without a separate supported integration.

Use the public project key from the DataSag project you are inspecting. A test on a preview domain does not confirm that the production domain has the same code or settings.

Track custom events in Shopify storefront themes

  1. For a storefront click goal, add data-datasag-goal to the intended theme link or button. Choose a name such as add_to_cart_click that accurately describes the interaction the browser observes.
  2. If you need confirmed cart or checkout outcomes, integrate with the actual success result supported by your storefront code. The theme snippet alone cannot confirm that an order was paid or that every checkout document was measured.
  3. Publish the intended theme and test the real product interaction. Inspect the named payload and ensure another handler is not also reporting it. Verify revenue through a separate supported payment integration before using purchase terminology.

The live theme records a precisely named storefront action and keeps paid-order verification separate.

Complete the collection checks

  1. Write the event definition first. For example, signup_click means a visitor pressed a signup link, while signup_completed means your application confirmed account creation.
  2. For click intent, add data-datasag-goal to the element. The tracker delegates clicks, so you do not also need a JavaScript handler for the same goal.
  3. For a completed action, call the JavaScript API in the success handler. Wait for the tracker to be available. An optional guard avoids a crash but intentionally drops the event if the tracker has not loaded.
  4. Send only the context needed for the report, such as a form or plan name. Do not include email addresses, passwords, payment details or freeform form contents.
  5. Complete one successful and one failed attempt. Inspect /api/track for the exact eventName and properties. Only the successful attempt should emit a completed-action event.
  6. Check the event report available to your plan. Collection and access to reports are separate; review current plan details before depending on a particular report.
<!-- Click intent: use this OR your own click handler -->
<a href="/signup" data-datasag-goal="signup_click">Create account</a>

// JavaScript: inside the confirmed-success handler
window.datasag?.track('signup_completed', { form: 'main_signup' });

For a storefront click goal, add data-datasag-goal to a theme button or link. Use a verified payment integration for revenue. Do not label an add-to-cart click as a paid purchase.

What a successful check looks like

A controlled successful action produces one event with the agreed name. A validation failure does not emit a success event. Network evidence matches the report definition.

Record the public path you tested, the browser state, the approximate time and the observed request. Check one direct page load and one later navigation so the result covers more than the homepage.

Common mistake

A goal attribute on a submit button measures clicks, including attempts that fail. Do not report those clicks as completed signups or purchases.

Installation snippet for Shopify storefront themes

The shared installation belongs in layout/theme.liquid before the closing head tag. Use this as the installation reference while checking the procedure above.

<script defer src="https://www.datasag.com/tracker.js" data-datasag-key="YOUR_PUBLIC_KEY"></script>

Related Shopify storefront themes guides

Full Shopify storefront themes setup guide · Search and AI visibility

References

Official Shopify storefront themes documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.