JavaScript Client
Documentation for the Trench JavaScript client
Overview
trench-js
is a client library for both web and Node.js environments that allows you to send events to any Trench instance. This library is designed to be easy to use and integrate into your existing projects. The library is built on top of Analytics and supports all of its methods. It can be installed via a package manager or via a CDN script tag.
Installation via package manager
Install trench-js
using your preferred package manager:
You can now initialize the client with your Trench instance URL and public API key:
For example, you can identify a user like this:
And track an event like this:
Or to record a trigger page view:
Installation via CDN script tag
Alternatively, you can use the CDN version:
This will automatically add the trench
object to the global scope and you can start tracking events automatically as autoCaptureEvents
is set to true
by default.
Was this page helpful?