Load DataEasy from your code
An official npm package is coming soon. Until then, load the hosted script from your code as shown below — it's the same tracker.
If you'd rather not touch your HTML template (Vue, Svelte, Angular, Astro islands…), inject the script from your app's entry file:
analytics.js
export function loadDataEasy({ websiteId, domain, apiUrl } = {}) {
if (typeof window === "undefined" || document.querySelector("script[data-website-id]")) return;
// Queue goals sent before the tracker is ready.
window.dataeasy = window.dataeasy || function () {
(window.dataeasy.q = window.dataeasy.q || []).push(arguments);
};
const script = document.createElement("script");
script.defer = true;
script.src = "https://dataeasy.app/js/script.js";
script.dataset.websiteId = websiteId;
if (domain) script.dataset.domain = domain;
if (apiUrl) script.dataset.apiUrl = apiUrl;
document.head.appendChild(script);
}
export const track = (goal, props) => window.dataeasy?.(goal, props);main.js
import { loadDataEasy, track } from "./analytics";
loadDataEasy({ websiteId: "YOUR_WEBSITE_ID", domain: "yourdomain.com" });
// later
track("signup", { method: "google" });The tracker reads its options from the data-* attributes of its own script element, so dataset.websiteId becomes data-website-id. See Script configuration for every option.