DataSag guides · Updated 27 October 2026
Track custom events on Hexo
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 Hexo.
Start with the Hexo installation
Find the active Hexo theme and its shared layout, such as themes/YOUR_THEME/layout/layout.ejs, or the head partial that layout includes. Add the deferred script once in head, preserving the body placeholder and the theme's template language. Regenerate and deploy the public files before testing.
Hexo templates can choose another layout or disable layout in front matter. Theme updates can overwrite direct edits, so maintain the customization through your theme's supported override or source-control workflow. An unused theme directory cannot affect the current build.
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 Hexo
- Add a goal attribute to an owned link or button in the active theme, using its actual template language. If the interaction comes from post content, inspect the generated HTML to verify the processor preserved your attribute.
- For confirmed success, use browser JavaScript that receives the successful result from the form service or application. Keep the event call out of Hexo helpers and generation hooks, which execute without a visitor browser.
- Test the interaction on an article and another template that reuses it. If your theme replaces content through client navigation, check that custom listeners initialize once per element and do not emit duplicate events after returning.
Theme interactions record the defined browser boundary, including any client-navigation lifecycle the selected theme introduces.
Complete the collection checks
- 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.
- 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.
- 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.
- 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.
- 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.
- 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 click goal, add data-datasag-goal to markup in the active theme or supported post HTML. Confirmed form events require a browser success callback; Hexo generation and deployment commands cannot establish visitor conversions.
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 Hexo
The shared installation belongs in the head of the active theme layout or its shared head partial. 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 Hexo guides
References
Official Hexo documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.