This documentation provides guidance on how to integrate the June SDK into your web-based application directly in the browser. The June SDK allows you to track user interactions and events, offering robust functionality for your analytics needs.
Getting started
Installation
Unlike npm or yarn installation used in Node.js or React environments, for a pure browser environment, you would typically load the SDK using a script tag. Here is an example of how to load the June SDK on your webpage:
The name of the event you’re tracking. You can read more about the track method and recommended event names.
Required
properties
Object
A dictionary of properties for the event. If the event was "Added to Cart", it might have properties like price and productType.
Optional
options
Object
A dictionary of options. For example, enable or disable specific destinations for the call. Note: If you do not pass a properties object, pass an empty object (like {}) before options.
Optional
callback
Function
A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first.
Optional
Identifying Users & Setting User Traits
To identify users, you can use the identify method:
The database ID for the user. If you don’t know who the user is yet, you can omit the userId and just record traits. You can read more about identities in the identify reference.
Optional
traits
Object
A dictionary of traits you know about the user, like email or name. You can read more about traits in the identify reference.
Optional
options
Object
A dictionary of options. For example, enable or disable specific destinations for the call. Note: If you do not pass a traits object, pass an empty object (like {}) before options.
Optional
callback
Function
A function executed after a timeout of 300 ms, giving the browser time to make outbound requests first.
Optional
Page Tracking
In order to track the pages viewed by the user, use the page method:
Note: In analytics.js a page call is included in the snippet by default just after analytics.load. Many destinations require this page event to be fired at least once per page load for proper initialization. You may add an optional name or properties to the default call, or call it multiple times per page load if you have a single-page application.
Parameters:
Parameter
Type
Description
Required
category
String
The category of the page. Useful for cases like ecommerce where many pages might live under a single category. Note: if you pass only one string to page it is assumed to be name. You must include a name to send a category.
Optional
name
String
The name of the page.
Optional
properties
Object
A dictionary of properties of the page. Note: June SDK collects url, title, referrer, and path automatically. This defaults to a canonical URL if available, and falls back to document.location.href.
Optional
options
Object
A dictionary of options. For example, enable or disable specific destinations for the call. Note: If you do not pass a properties object, pass an empty object (like {}) before options.
Optional
callback
Function
A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first.
Optional
Grouping Users
To group users by organization or company, use the group method:
A dictionary of traits for the group. Example traits for a group include address, website, and employees.
Optional
options
Object
A dictionary of options. For example, enable or disable specific destinations for the call. Note: If you do not pass a properties object, pass an empty object (like {}) before options.
Optional
callback
Function
A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first.