Vanilla JS

this doc will demonstrate how you can add the fastest, simplest and cheapest privacy friendly analytics to your vanilla js project in 2 minutes

if you get stuck or not feeling confident, i will personally help you integrate it :) book a time on my calendly

automatic page view tracking

create a rustalytics.js file and add the following code. REPLACE <your-api-key> with your api key

!function(t,e,s,a,i,n,c,p){t[a]=t[a]||function(){(t[a].q=t[a].q||[]).push(arguments)},n=e.createElement(s),c=e.getElementsByTagName(s)[0],n.async=1,n.src=i,c.parentNode.insertBefore(n,c)}(window,document,"script","rustalytics","https://rustalytics.dev/rustalytics.js"),rustalytics("init",{apiToken:"<your-api-key>"});

link the file you just created to your html's head tag (on every page)

<script src="/rustalytics.js"></script>

custom events

custom events on ANY html element

after linking the file to your html's head tag, you can track custom events on ANY html element by adding a data-rustalytics attribute. The value should be the event name you want to track, for example: "clicked-checkout" or if you are a/b testing you can add the variation: "clicked-checkout-variation-a"

<a data-rustalytics="clicked-checkout" href="/checkout">checkout</a>

track custom events without html elements

if you want to track a custom event without an html element, you can use the following function in your javascript file:

rustalytics("event-name");