Developer ResourcesSDKs

Javascript (Client-side)

Installation

The schematic-js SDK is hosted here. Use npm or your preferred package manager to install:

$npm install @schematichq/schematic-js

Once installed, you can submit requests using your publishable key.

If you prefer to install the client-side JavaScript library using a script tag, you can load it from our CDN using the following URL: https://cdn.schematichq.com/js/schematic.js

Initialization

Initialize the SDK in the following way:

1var schematic = new Schematic("your-api-key");

Usage example

Once the SDK is initialized, you may submit requests. Below is an example of identifying a user and submitting a usage event to Schematic.

1// Send an identify event
2const userId = "my-user-id";
3const keys = {
4 id: userId,
5};
6const traits = {
7 anykey: "anyval",
8};
9const company = {
10 name: "My Company",
11 keys: {
12 id: "my-company-id",
13 },
14 traits: {
15 location: "Atlanta, GA",
16 }
17};
18schematic.identify({ keys, traits, company });
19
20// Send a track event
21const event = "query";
22const traits = {};
23const company = {};
24const user = {};
25
26schematic.track({
27 event: "query",
28 traits: {
29 feature: "feat_cns2asuKAG2",
30 },
31 company: {
32 id: "my-company-id",
33 },
34 user: {
35 id: "my-user-id",
36 },
37});

The Javasript SDK references companies or users by their Schematic ID using the id key or by any key you have defined and passed to Schematic previously.

React Native

This library uses uuid. In order for this to work in a React native context, you must also provide a shim for crypto.getRandomValues as described in the uuid documentation.