diff --git a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/_import-and-initialize.mdx b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/_import-and-initialize.mdx index defb8f01..b69a5c38 100644 --- a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/_import-and-initialize.mdx +++ b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/_import-and-initialize.mdx @@ -31,6 +31,12 @@ import RubyImport from "!!raw-loader!./ruby/import.rb"; import FlutterImport from "!!raw-loader!./flutter/import.dart"; +import DartImport from "!!raw-loader!./dart/import.dart"; + +import RustImport from "!!raw-loader!./rust/initialize.rs"; + +import LiquidImport from "!!raw-loader!./liquid/initialize.liquid"; + Once the SDK is installed, it can be initialized in your project. :::info @@ -102,9 +108,9 @@ directly into the Provider component, like so: ```jsx ReactDOM.render( - + - , + , document.getElementById("root") ); ``` @@ -367,18 +373,170 @@ custom event logger), it can be done as following: - + + +{DartImport} + +**SDK Options** + +| Config | Type | Required? | Default | Description | +| :---------------------- | :-------------------------------- | :-------: | :---------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| endpoint | `String` | ✅ | `null` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` | +| apiKey | `String` | ✅ | `null` | Your API key which can be found on the Web Console. | +| environment | `String` | ✅ | `null` | The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure. | +| application | `String` | ✅ | `null` | The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running. | +| retries | `int` | ❌ | `5` | The number of retries before the SDK stops trying to connect. | +| timeout | `int` | ❌ | `3000` | An amount of time, in milliseconds, before the SDK will stop trying to connect. | +| contextEventLogger | `ContextEventLogger` | ❌ | `null` | A callback interface which runs after SDK events. See [Using a Custom Event Logger](#using-a-custom-event-logger) below | + +**Advanced Configuration** + +For advanced use cases where you need custom HTTP clients or data providers, you can still use the manual configuration approach: + +```dart +final clientConfig = ClientConfig() + ..setEndpoint("https://your-company.absmartly.io/v1") + ..setAPIKey("YOUR-API-KEY") + ..setApplication("website") + ..setEnvironment("development"); + +final httpClientConfig = DefaultHTTPClientConfig() + ..setMaxRetries(3) + ..setConnectTimeout(5000); + +final client = Client.create( + clientConfig, + httpClient: DefaultHTTPClient.create(httpClientConfig), +); + +final sdkConfig = ABsmartlyConfig.create() + ..setClient(client); + +final sdk = ABsmartly(sdkConfig); +``` + + + + {FlutterImport} **SDK Options** -| Config | Type | Required? | Default | Description | -| :---------- | :-------------------------------- | :-------: | :---------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| endpoint | `string` | ✅ | `undefined` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` | -| apiKey | `string` | ✅ | `undefined` | Your API key which can be found on the Web Console. | -| environment | `"production"` or `"development"` | ✅ | `undefined` | The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure. | -| application | `string` | ✅ | `undefined` | The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running. | +| Config | Type | Required? | Default | Description | +| :---------------------- | :-------------------------------- | :-------: | :---------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| endpoint | `String` | ✅ | `null` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` | +| apiKey | `String` | ✅ | `null` | Your API key which can be found on the Web Console. | +| environment | `String` | ✅ | `null` | The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure. | +| application | `String` | ✅ | `null` | The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running. | +| retries | `int` | ❌ | `5` | The number of retries before the SDK stops trying to connect. | +| timeout | `int` | ❌ | `3000` | An amount of time, in milliseconds, before the SDK will stop trying to connect. | +| contextEventLogger | `ContextEventLogger` | ❌ | `null` | A callback interface which runs after SDK events. See [Using a Custom Event Logger](#using-a-custom-event-logger) below | + +**Advanced Configuration** + +For advanced use cases where you need custom HTTP clients or data providers, you can still use the manual configuration approach: + +```dart +final clientConfig = ClientConfig() + ..setEndpoint("https://your-company.absmartly.io/v1") + ..setAPIKey("YOUR-API-KEY") + ..setApplication("website") + ..setEnvironment("development"); + +final httpClientConfig = DefaultHTTPClientConfig() + ..setMaxRetries(3) + ..setConnectTimeout(5000); + +final client = Client.create( + clientConfig, + httpClient: DefaultHTTPClient.create(httpClientConfig), +); + +final sdkConfig = ABsmartlyConfig.create() + ..setClient(client); + +final sdk = ABsmartly(sdkConfig); +``` + + + + + +{RustImport} + +**SDK Options** + +| Config | Type | Required? | Default | Description | +| :---------- | :----------------------------------- | :-------: | :-------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| endpoint | `&str` or `String` | ✅ | `undefined` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` | +| api_key | `&str` or `String` | ✅ | `undefined` | Your API key which can be found on the Web Console. | +| environment | `&str` or `String` | ✅ | `undefined` | The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure. | +| application | `&str` or `String` | ✅ | `undefined` | The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running. | +| retries | `u32` | ❌ | `5` | The number of retries before the SDK stops trying to connect. | +| timeout_ms | `u64` | ❌ | `3000` | An amount of time, in milliseconds, before the SDK will stop trying to connect. | +| agent | `String` | ❌ | `None` | Custom user agent string for HTTP requests. | + +**Builder Pattern** + +The Rust SDK supports a fluent builder pattern for optional configuration: + +```rust +let config = SDKConfig::new( + "https://your-company.absmartly.io/v1", + "YOUR-API-KEY", + "website", + "development", +) +.with_timeout(5000) +.with_retries(3) +.with_agent("my-app/1.0"); + +let sdk = ABsmartly::new(config)?; +``` + + + + + +{LiquidImport} + +**SDK Options** + +| Config | Type | Required? | Default | Description | +| :---------- | :----------------------------------- | :-------: | :-------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| endpoint | `string` | ✅ | `undefined` | The URL to your API endpoint. Most commonly `"your-company.absmartly.io"` | +| apiKey | `string` | ✅ | `undefined` | Your API key which can be found on the Web Console. | +| environment | `"production"` or `"development"` | ✅ | `undefined` | The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure. | +| application | `string` | ✅ | `undefined` | The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running. | +| units | `object` | ✅ | `{}` | An object containing unit identifiers (e.g., session_id, customer_id) used for experiment assignment. | + +**Server-Side Rendering** + +For Shopify Liquid templates, ABsmartly can be integrated server-side to pre-fetch context data: + +```liquid +{% comment %} + Render the ABsmartly initialization snippet + This can be used to embed pre-fetched context data +{% endcomment %} +{% render 'absmartly-init', + session_id: request.cookie.session_id, + customer_id: customer.id +%} +``` + +**Using ABsmartly in Templates** + +Once initialized, you can use ABsmartly treatments in your Liquid templates: + +```liquid +{% if absmartly.treatment.banner_color == 1 %} + +{% else %} + +{% endif %} +``` diff --git a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/dart/import.dart b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/dart/import.dart new file mode 100644 index 00000000..3d617b38 --- /dev/null +++ b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/dart/import.dart @@ -0,0 +1,10 @@ +import 'package:absmartly_sdk/absmartly_sdk.dart'; + +void main() async { + final sdk = ABsmartly.create( + endpoint: 'https://your-company.absmartly.io/v1', + apiKey: 'YOUR-API-KEY', + application: 'website', + environment: 'development', + ); +} diff --git a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/flutter/import.dart b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/flutter/import.dart index c49890cb..d4cada21 100644 --- a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/flutter/import.dart +++ b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/flutter/import.dart @@ -1,11 +1,8 @@ -void main() async{ - final ClientConfig clientConfig = ClientConfig() - ..setEndpoint("https://your-company.absmartly.io/v1") - ..setAPIKey("YOUR API KEY") - ..setApplication("website") - ..setEnvironment("development"); - - final ABSmartlyConfig sdkConfig = ABSmartlyConfig.create() - .setClient(Client.create(clientConfig)); - final ABSmartly sdk = ABSmartly(sdkConfig); +void main() async { + final sdk = ABsmartly.create( + endpoint: 'https://your-company.absmartly.io/v1', + apiKey: 'YOUR-API-KEY', + application: 'website', + environment: 'development', + ); } diff --git a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/liquid/initialize.liquid b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/liquid/initialize.liquid new file mode 100644 index 00000000..e0cd0971 --- /dev/null +++ b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/liquid/initialize.liquid @@ -0,0 +1,29 @@ +{% comment %} + Initialize the ABsmartly SDK in your Shopify theme + Add this to your theme.liquid layout file, typically in the section +{% endcomment %} + + + +{% comment %} + Include the ABsmartly client-side SDK + This should be loaded before any code that uses the ABsmartly context +{% endcomment %} + + + diff --git a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/ruby/import.rb b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/ruby/import.rb index dd792c8c..cbf7260c 100644 --- a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/ruby/import.rb +++ b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/ruby/import.rb @@ -1,4 +1,4 @@ -Absmartly.configure_client do |config| +ABsmartly.configure_client do |config| config.endpoint = "https://your-company.absmartly.io/v1" config.api_key = "YOUR-API-KEY" config.application = "website" diff --git a/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/rust/initialize.rs b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/rust/initialize.rs new file mode 100644 index 00000000..78e06cce --- /dev/null +++ b/docs/APIs-and-SDKs/SDK-Documentation/getting-started/import-and-initialize/rust/initialize.rs @@ -0,0 +1,15 @@ +use absmartly_sdk::{ABsmartly, SDKConfig}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let config = SDKConfig::new( + "https://your-company.absmartly.io/v1", + "YOUR-API-KEY", + "website", + "development", + ); + + let sdk = ABsmartly::new(config)?; + + Ok(()) +}