Getting started with the Context Suite event stream is straightforward. Our primary client library is based on Jitsu, a flexible and robust open-source data collection library. Below are the common installation methods for different environments.
In the Browser (Client-Side)
The easiest way to start sending events from a website or web application is to add the Jitsu script tag directly to your HTML file. This is the ideal method for capturing user interactions like page views and clicks.
Add the Script to Your HTML
Place the following
<script>tag in the<head>section of your website's HTML. This will load the Jitsu library asynchronously from a CDN, so it won't block the rendering of your page.HTMLhtml1<script> 2 (function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return; 3 js=d.createElement(s);js.id=id;js.src="[https://cdn.jitsu.com/v2/jitsu.min.js](https://cdn.jitsu.com/v2/jitsu.min.js)"; 4 fjs.parentNode.insertBefore(js,fjs);}(document,'script','jitsu-sdk')); 5</script>Initialize the Library
After including the script, you need to initialize it with your unique
write key. This key directs the events to your specific data stream in the Context Suite. You can find this key in your project settings. Add this second script snippet right after the first one.HTMLhtml1<script> 2 window.jitsu = window.jitsu || (function(){(window.jitsu.q=window.jitsu.q||[]).push(arguments)}); 3 jitsu('init', { 4 key: 'YOUR_WRITE_KEY_HERE', 5 log_level: 'DEBUG' // Optional: 'DEBUG', 'INFO', 'ERROR'. Defaults to 'INFO'. 6 }); 7</script>
Now the jitsu object is available globally in your browser, and you can start sending events like jitsu.page() or jitsu.track('Button Clicked').
Ready to send your first event? Check out Getting Started for a complete walkthrough, or explore the different Event Types available.
In Node.js (Server-Side)
For sending events from your backend services, such as when a user account is created or a payment is processed, you can use the Jitsu NPM package. This ensures that critical events are sent reliably and securely.
Install the NPM Package
Open your terminal and run the following command to add the Jitsu SDK to your project:
Bashbashnpm install @jitsu/sdk-jsImport and Initialize in Your Application
In your JavaScript or TypeScript file, import the library and create an instance, again providing your
write key.JavaScriptjavascript1import jitsu from "@jitsu/sdk-js"; 2 3const jitsuClient = jitsu({ 4 key: "YOUR_WRITE_KEY_HERE" 5}); 6 7// You can now use the client to send events 8// await jitsuClient.track('User Registered', { plan: 'premium' });Sending events from the server-side is highly recommended for any action that is critical to your business logic or involves sensitive data.
For examples of server-side events with rich commerce data, see the Commerce and Products documentation.
Other Environments (Python, Java, Go, etc.)
For other server-side languages, we provide dedicated libraries that follow the same principles. The general process is always:
- Add the appropriate library/package to your project.
- Initialize a client instance with your
write key. - Use the client instance to send
track,identify, andgroupevents.
Please refer to the specific documentation for your language of choice for detailed installation and usage instructions.