HTML Script
Track your data via the HTML Script for Vemetric.
The HTML Script is the simplest way to track your data on any website.
Below you can see how to initialize and configure the HTML Script, as well as all the available functions.
If you’re looking for a more modern way to integrate Vemetric into your webapp, checkout the Web (Browser) SDK that’s offered via a NPM package.
Installation
Copy the following code snippet into the <head>
section of your website so that it loads on every page.
Replace
YOUR_PROJECT_TOKEN
with the unique token for your project (found in the project settings).
Configuration
It’s possible to configure Vemetric by passing data-
attributes on the script tag additionaly to the data-token
attribute.
data-host
Here you can specify a different host for the Vemetric API.
Necessary if you want to use a proxy for tracking your data via your own domain.
data-track-page-views
Whether to track page views automatically.
Listens to any kind of changes of the URL (hash, pathname, search, etc.) and records a page view event. If disabled, you need to track page views manually.
data-track-outbound-links
data-track-data-attributes
Whether to listen to data-vmtrc
attributes on elements for sending custom
events.
data-mask-paths
An array of paths to mask from the URL. Helpful if you mask sensitive information in the URL (e.g. user IDs) or
group page views by a specific path (e.g. /project/*
).
Methods
Below you can find all the available methods and their functionality.
trackEvent
The main method to track any kind of event.
The first argument is the event name. The second argument is optional and can be an object with the following properties (also both optional):
eventData
: An object containing the meta data of the event so you can later filter byuserData
: An object to update the user data. Only relevant for identified users.set
: An object containing the user data to set, overriding existing values.setOnce
: An object containing the user data to set once, only if the keys do not exist yet.unset
: An array of keys to remove from the user data.
Checkout the tracking custom events section to learn more.
identify
With this function you can identify a user. All following events will be associated with this user. Checkout the docs about User identification to learn more about how it works.
The function takes the following parameters:
identifier
: (Required): The unique identifier for the user. We recommend to use the user’s primary id in your database.displayName
: Optional: will be used to display the users’ name in VemetricallowCookies
: Optional: Whether to use cookies to ensure smoother tracking.data
: Optional: An object to update the user data.set
: An object containing the user data to set, overriding existing values.setOnce
: An object containing the user data to set once, only if the keys do not exist yet.unset
: An array of keys to remove from the user data.
getUserIdentifier
Returns the identifier of the currently identified user. Returns null
if no user is identified.
updateUser
Updates the data of the currently identified user.
The first parameter is an object with the following properties:
set
: An object containing the user data to set, overriding existing values.setOnce
: An object containing the user data to set once, only if the keys do not exist yet.unset
: An array of keys to remove from the user data.
resetUser
Should be called when the user logs out. From then on, all events will be tracked as anonymous.
enableTrackPageViews
A function to enable automatic page view tracking after initialization. Only needed if trackPageViews
was disabled.
enableTrackOutboundLinks
A function to enable outbound link tracking after initialization. Only needed if trackOutboundLinks
was disabled.
enableTrackDataAttributes
A function to enable data attribute tracking after initialization. Only needed if trackDataAttributes
was disabled.
Learn more about tracking custom events via data attributes.
trackPageView
A function to manually track a page view from the current URL. Only needed if trackPageViews
was disabled.
trackPageLeave
A function to manually track a page leave. Only needed if trackPageViews
was disabled.
Overview of the available Vemetric SDKs
Track your data via the Web (Browser) SDK for Vemetric.