Javascript (Client-side)
Javascript (Client-side)
Javascript (Client-side)
schematic-js is a client-side JavaScript SDK for tracking event-based usage, identifying users, and checking flags using Schematic.
You can use Schematic to identify users; after this, your subsequent track events and flag checks will be associated with this user.
A number of these examples use keys to identify companies and users. Learn more about keys here.
By default, checkFlag will perform a network request to get the flag value for this user. If you’d like to check all flags at once in order to minimize network requests, you can use checkFlags:
Alternatively, you can run in websocket mode, which will keep a persistent connection open to the Schematic service and receive flag updates in real time:
The SDK includes built-in fallback behavior you can use to ensure your application continues to function even when unable to reach Schematic (e.g., during service disruptions or network issues).
When checkFlag cannot reach Schematic, it uses fallback values in the following priority order:
checkFlag callflagCheckDefaults or flagValueDefaults options when initializing the SDKfalse if no fallback is configuredWhen events (track, identify) cannot be sent due to network issues, they are automatically queued and retried:
maxEventQueueSize)maxEventRetries)In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as outlined above. The WebSocket will also automatically attempt to re-establish it’s connection with Schematic using an exponential backoff.
For debugging and development, Schematic supports two special modes:
Enables console logging of all Schematic operations:
Prevents network requests and returns fallback values for all flag checks:
Offline mode automatically enables debug mode to help with troubleshooting.
MIT
Need help? Please open a GitHub issue or reach out to support@schematichq.com and we’ll be happy to assist.