Hooks stages
LaunchDarkly SDKs provide the following series of hooks:| Series | Stages | Execution |
|---|---|---|
| Evaluation | beforeEvaluation, afterEvaluation | When you include a hook in your SDK configuration, the SDK executes these two stages before and after you evaluate a feature flag. |
| Identify | beforeIdentify, afterIdentify | When you include a hook in your SDK configuration, the SDK executes these two stages before and after you identify a context. Only available for client-side SDKs. |
| Track | afterTrack | When you include a hook in your SDK configuration, the SDK executes this stage after you send a custom event. |
Server-side SDKs
This feature is available in the following SDKs:.NET (server-side)
Expand .NET (server-side) code sample
Expand .NET (server-side) code sample
To use hook functionality with the .NET (server-side) SDK, first import the To learn more, read
LaunchDarkly.Sdk.Server.Hooks namespace. Then, define a new hook. This class must derive from the Hook class and override its methods. Finally, reference the hook in the configuration options when you initialize the SDK client.Here’s how:Hooks.Go
Expand Go code sample
Expand Go code sample
Java
Expand Java code sample
Expand Java code sample
Node.js (server-side)
Expand Node.js (server-side) code sample
Expand Node.js (server-side) code sample
To use hook functionality with the Node.js (server-side) SDK, first define a new hook. This class must extend the You can also add a hook to an existing client using the To learn more, read
Hook interface. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:addHook method:Hook.PHP
Expand PHP code sample
Expand PHP code sample
To use hook functionality with the PHP SDK, first define a new hook. This class must extend the You can also add a hook to an existing client using the To learn more, read the SDK API documentation.
LaunchDarkly\Hooks\Hook abstract class and implement getMetadata. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:addHook method:Python
Expand Python code sample
Expand Python code sample
To use hook functionality with the Python SDK, first define a new hook. This class must inherit from You can also add a hook to an existing client using the To learn more, read
ldclient.hook.Hook. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:add_hook method:ldclient.hook.If you are working with forking processes, any configuration that you provide to the SDK must survive the forking process independently. We recommend that you add any hooks after a postfork() call, unless you are certain they can survive the forking process. To learn more, read Initialize the client and ldclient.postfork.Ruby
Expand Ruby code sample
Expand Ruby code sample
To use hook functionality with the Ruby SDK, first define a new hook. This class must include the You can also add a hook to an existing client using the To learn more, read
Hooks mixin. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:add_hook method:Hooks.If you are working with forking processes, any configuration that you provide to the SDK must survive the forking process independently. We recommend that you add any hooks after a postfork() call, unless you are certain they can survive the forking process. To learn more, read Initialize the client and postfork.Client-side SDKs
This feature is available in the following SDKs:- Android
- iOS
- JavaScript
- React Native
- Vue: The Vue SDK relies on the JavaScript SDK for this functionality.
Android
Expand Android code sample
Expand Android code sample
To use hook functionality with the Android SDK, first define a new hook. This class must extend the You can also add a hook to an existing client using the To learn more, read
Hook class. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:setHooks method:Hook and HooksConfigurationBuilder.iOS
Expand iOS code sample
Expand iOS code sample
JavaScript
Expand JavaScript code sample
Expand JavaScript code sample
To use hook functionality with the JavaScript SDK, first define a new hook. This class must extend the You can also add a hook to an existing client using the To learn more, read
Hook interface. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:addHook method:Hook.React Native
Expand React Native code sample
Expand React Native code sample
To use hook functionality with the React Native SDK, first define a new hook. This class must extend the You can also add a hook to an existing client using the To learn more, read
Hook interface. Then, reference the hook in the configuration options when you initialize the SDK client.Here’s how:addHook method:Hook.Vue
Expand Vue code sample
Expand Vue code sample
The Vue SDK relies on the JavaScript SDK for hooks. Define a hook that implements the You can also add a hook later. Retrieve the client with
Hook interface, then set the hooks option in ldOptions when you install the plugin or create a provider.Here’s how:useLDClient() and call addHook().To learn more about defining a hook, read JavaScript.