Svelte is a lightweight JavaScript framework for building web applications.
Table of contents:
Integrating MetricsWave with Svelte is easy. You only need to add the Script inside the <svelte:head>
tag.
Something like this is enough.
<svelte:head>
<!-- MetricsWave Script -->
<script defer
event-uuid="00000000-0000-0000-0000-000000000000"
src="https://tracker.metricswave.com/js/visits.js">
</script>
</svelte:head>)
It's important that this script should be included on all the pages of your application, maybe you can use a layout or extend the app from this component.
To trigger events whenever you want you will need to use the API.
You have multiple options to do this, but a simple one it's to create a function like the next and use it everywhere in your application.
You only need to pass the trigger UUID and the parameters of your event.
export function triggerEvent(eventUuid: string, params: Object = {}) {
if (!app.isProduction) {
console.log(`[EventTracker] ${eventUuid}`, params)
return
}
fetch(`https://metricswave.com/webhooks/${eventUuid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify(params),
})
}
Start for free, and upgrade your account at any moment.