Web
LogSnag's web library automatically tracks page views and makes it extremely easy to track custom events.
Add the following script tag to your HTML file to install the web library. Please don't forget to update the
TOKEN
and PROJECT_NAME
values with your own values.<script async="true" src="https://cdn.logsnag.com/web/ls.js"></script>
<script>
window.lsq = window.lsq || [];
window.ls = window.ls || ((...args) => window.lsq.push(args));
window.ls("setConfig", "<TOKEN>", "<PROJECT_NAME>");
</script>
Please ensure that your token is set to "Public" and its roles are limited to the project you're tracking.
This library requires a user id to be set before it starts tracking your events. You can set the user id by calling the
window.ls("setUserId", "<USER_ID>")
function. For example, you could set the user id to the user's email address. Once you've set the user id, LogSnag will start tracking page views and any custom events that you track.<script>
window.ls("setUserId", "<SOME_USER_ID>");
</script>
Tracking custom events is as simple as defining a data attribute on any element. For example, let's track when a user upgrades their plan.
<button
data-event="Upgraded Plan"
>
Upgrade to Pro
</button>
You may add custom properties to your events by defining a data attribute on any element. Remember, the only required property is
data-event
, everything else is optional.<button
data-event="Upgraded Plan"
data-channel="billing"
data-icon=":moneybag:"
data-tag-plan="Pro"
data-tag-period="Monthly"
data-tag-price="9.99"
>
Upgrade to Pro
</button>
Last modified 10d ago