Developer guide
Follow this section to install and configure the SDK, and learn about advanced features.Getting started
Installing the Go client
To install the Kameleoon Go SDK, use thego get command and install our package directly from our GitHub repository. Simply run the command below:
Additional configuration
To provide additional settings for the Go SDK, you can use a configuration file, which lets you customize the SDK’s behavior. You can download a sample configuration file here. We recommend installing this file to the default path/etc/kameleoon/client-go.yaml, which will be read automatically. If you need to customize this path, you can provide an additional argument to the NewClient() method. Either specify a string that indicates an alternative path to the configuration file, or add a JavaScript object (map) containing the configuration.
The current version of the Go SDK has the following keys available in the configuration file:
To learn more about
client_id and client_secret, and instructions on how to obtain them, please refer to this article. It’s worth noting that our Go SDK utilizes the Automation API and follows the OAuth 2.0 client credentials flow.Initializing the Kameleoon Client
Once you have installed our SDK in your application, you must initialize Kameleoon. All interactions with the SDK, such as triggering an experiment, are accomplished via the object (the Kameleoon client) created using theNewClient() method.
You can customize the behavior of the SDK (for example, the environment or the credentials) by providing a configuration object.
Activating a feature flag
Assigning a unique ID to a user
To assign a unique ID to a user, you can use theGetVisitorCode() method. If a visitor code doesn’t exist (from the request headers cookie), the method generates a random unique ID or uses a defaultVisitorCode that you would have generated. The ID is then set in a response headers cookie.
If you are using Kameleoon in Hybrid mode, calling the GetVisitorCode() method ensures that the unique ID (visitor code) is shared between the application file engine.js (previously named, kameleoon.js) and the SDK.
Retrieving a flag configuration
To implement a feature flag in your code, you must first create the feature flag in your Kameleoon account. To determine the status or variation of a feature flag for a specific user, you should use theGetVariation() or IsFeatureActive() method to retrieve the configuration based on the featureKey.
The GetVariation() method handles both simple feature flags with ON/OFF states and more complex flags with multiple variations. The method retrieves the appropriate variation for the user by checking the feature rules, assigning the variation, and returning it based on the featureKey and visitorCode.
The IsFeatureActive() method can be used if you want to retrieve the configuration of a simple feature flag that has only an ON or OFF state, as opposed to more complex feature flags with multiple variations or targeting options.
If your feature flag has associated variables (such as specific behaviors tied to each variation) GetVariation() also enables you to access the Variation object, which provides details about the assigned variation and its associated experiment. This method checks whether the user is targeted, finds the visitor’s assigned variation, and saves it to storage. When GetVariationOptParams.Track=true, the SDK will send the exposure event to the specified experiment on the next tracking request, which is automatically triggered based on the SDK’s tracking_interval. By default, this interval is set to 1000 milliseconds (1 second).
The GetVariation() method allows you to control whether tracking is done. If GetVariationOptParams.Track=false, no exposure events will be sent by the SDK. This is useful if you prefer not to track data through the SDK and instead rely on client-side tracking managed by the Kameleoon engine, for example. Additionally, setting GetVariationOptParams.Track=false is helpful when using the GetVariations() method, where you might only need the variations for all flags without triggering any tracking events. If you want to know more about how tracking works, view this article
Adding data points to target a user or filter / breakdown visits in reports
To target a user, ensure you’ve added relevant data points to their profile before retrieving the feature variation or checking if the flag is active. Use theAddData() method to add these data points to the user’s profile.
To retrieve data points collected on other devices or to access past user data (collected client-side when using Kameleoon in Hybrid mode), use the GetRemoteVisitorData() method. This method asynchronously fetches data from the servers. It is important to call GetRemoteVisitorData() before retrieving the variation or checking if the feature flag is active, as this data might be required to assign a user to a given variation.
To learn more about available targeting conditions, see the detailed article on the subject.
Additionally, the data points you add to the visitor profile will be available when analyzing your experiments, allowing you to filter and break down your results by factors like device and browser. Kameleoon Hybrid mode automatically collects a variety of data points on the client-side, making it easy to break down your results based on these pre-collected data points. See the complete list here.
If you need to track additional data points beyond what’s automatically collected, you can use Kameleoon’s Custom Data feature. Custom Data allows you to capture and analyze specific information relevant to your experiments. Don’t forget to call the Flush*() method to send the collected data to Kameleoon servers for analysis.
To ensure your results are accurate, it’s recommended to filter out bots by using the
UserAgent data type.Tracking flag exposition and goal conversions
When a user completes a desired action (such as making a purchase), it is recorded as a conversion. To track conversions, use theTrackConversion() method and provide the required visitorCode and goalId parameters.
The conversion tracking request will be sent along with the next scheduled tracking request, which the SDK sends at regular intervals (defined by tracking_interval). If you prefer to send the request immediately, use the FlushVisitorInstantly() method.
Sending events to analytics solutions
To track conversions and send exposure events to your customer analytics solution, you must first implement Kameleoon in Hybrid mode. Then, use theGetEngineTrackingCode() method.
The GetEngineTrackingCode() method retrieves the unique tracking code required to send exposure events to your analytics solution. Using this method allows you to record events and send them to your desired analytics platform.
Cross-device experimentation
To support visitors who access an app from multiple devices, Kameleoon allows the synchronization of previously collected visitor data across each of the visitor’s devices and reconciliation of their visit history across devices through cross-device experimentation. Case studies and detailed information on how Kameleoon handles data across devices are available in the article on cross-device experimentation.Synchronizing custom data across devices
Although custom mapping synchronization is used to align visitor data across devices, it is not always necessary. Below are two scenarios where custom mapping sync is not required: Same user ID across devices If the same user ID is used consistently across all devices, synchronization is handled automatically without a custom mapping sync. It is enough to call theGetRemoteVisitorData() method when you want to sync the data collected between multiple devices.
Multi-server instances with consistent IDs
In complex setups involving multiple servers (for example, distributed server instances), where the same user ID is available across servers, synchronization between servers (with GetRemoteVisitorData()) is sufficient without additional custom mapping sync.
Customers who need additional data can refer to the GetRemoteVisitorData() method description for further guidance. In the below code, it is assumed that the same unique identifier (in this case, the visitorCode, which can also be referred to as userId) is used consistently between the two devices for accurate data retrieval.
If you want to sync collected data in real time, you need to choose the scope Visitor for your custom data.
Device A
Device B
Using custom data for session merging
Cross-device experimentation allows for combining a visitor’s history across each of their devices (history reconciliation). History reconciliation allows merging different visitor sessions into one. To reconcile visit history, useCustomData to provide a unique identifier for the visitor. For more information, see the dedicated documentation.
After cross-device reconciliation is enabled, calling GetRemoteVisitorData() with the parameter userId retrieves all known data for a given user.
Sessions with the same identifier will always be shown the same variation in an experiment. In the Visitor view of your experiment’s results pages, these sessions will appear as a single visitor.
The SDK configuration ensures that associated sessions always see the same variation of the experiment. However, there are some limitations regarding cross-device variation allocation. These limitations are outlined here.
Follow the activating cross-device history reconciliation guide to set up your custom data on the Kameleoon platform.
Afterwards, you can use the SDK normally. The following methods that may be helpful in the context of session merging:
GetRemoteVisitorData()with addedUniqueIdentifier(true)- to retrieve data for all linked visitors.TrackConversion()orFlush*()with addedUniqueIdentifier(true)data - to track some data for specific visitor that is associated with another visitor.
GetVisitorCode() method is used. After the user logs in, the anonymous visitor is associated with the user ID and used as a unique identifier for the visitor.
Using a custom bucketing key
By default, Kameleoon uses a unique, anonymous visitor ID (visitorCode) to assign users to feature flag variations. This ID is typically generated and stored on the user’s device (in a browser cookie for client-side and server-side SDKs—in persistent storage for mobile SDKs). However, in certain scenarios you may need to ensure all users of the same organization see the same variant of a feature flag.
The Custom Bucketing Key option allows you to override this default behavior by providing your own custom identifier for bucketing. This override ensures that Kameleoon’s assignment logic uses your specified key instead of the default visitorCode.
Use cases
Using a custom bucketing key is essential for maintaining consistency and accuracy in your feature flag assignments, particularly in these situations:- Account-level or organizational experiments: For B2B products or scenarios where you want to assign all users from the same organization to the same variation, you can use an identifier like an
accountId. Custom bucketing keys are crucial for A/B testing features that impact an entire team or company.
Technical details
When you configure a custom bucketing key for a feature flag, you provide Kameleoon with a specific identifier from your application’s data:- Providing the custom key: You provide your custom identifier to the Kameleoon SDK using the
AddData()method. In this method, you will pass your chosen custom bucketing key as aCustomDataobject. Here,newVisitorCoderefers to the identifier you wish to use for your bucketing (for example, the newuserIdoraccountId).
- Bucketing logic: Once a custom bucketing key is provided through the
AddData()method, all hash calculations for assigning users to variations will use thisnewVisitorCode(your custom key) instead of the defaultvisitorCode. Using thenewVisitorCodemeans that the bucketing decision is tied to your custom identifier, ensuring consistent assignments across various contexts where that identifier is present. - Data tracking and analytics: It’s crucial to note that while the
newVisitorCode(your custom key) is used for bucketing decisions, all subsequent data (tracking events and conversions, for example) is sent and associated with the originalvisitorCode. This separation ensures that your analytics accurately reflect individual user journeys and interactions within your experiment’s broader context, even when bucketing is performed at a higher level (like an account) or across multiple devices/sessions. Your original visitor data remains intact for comprehensive reporting.
Technical requirements
To effectively use a custom bucketing key:- The key must be a
string. - It must be unique for the entity you intend to bucket (for example, if using a
userId, each user’s ID should be unique). - The key must be available to the SDK at the exact moment the feature flag decision is evaluated for that user or request.
Targeting conditions
The Kameleoon SDKs support a variety of predefined targeting conditions that you can use to target users in your campaigns. For the list of conditions this SDK supports, see use visit history to target users. You can also use your own external data to target users.Logging
The SDK generates logs to reflect various internal processes and issues.Log levels
The SDK supports configuring limiting logging by a log level.Custom handling of logs
The SDK writes its logs to the console output by default. This behaviour can be overridden.Logging limiting by a log level is performed apart from the log handling logic.
Reference
This is a full reference documentation of the Go SDK.Initialization
Create()
Call this method before any others to initialize the SDK. This method is inKameleoonClientFactory. This creates an instance of KameleoonClient to manage all interactions between the SDK and your app.
Parameters
Return value
CreateFromFile()
Call this method before any others to initialize the SDK. This method is inKameleoonClientFactory. This creates an instance of KameleoonClient to manage all interactions between the SDK and your app.
Parameters
Return value
Forget()
TheForget method removes a KameleoonClient instance from the KameleoonClientFactory with the specified siteCode and frees resources used by the KameleoonClient instance. The KameleoonClient instance must not be used after calling the Forget method.
Parameters
WaitInit()
The initialization of the Kameleoon Client is not immediate, as it requires a server request to our CDN (Content Delivery Network) to retrieve the current configuration for all active experiments and feature flags. TheWaitInit method of the kameleoon.KameleoonClient allows you to wait until the KameleoonClient instance is ready for use.
Return value
Feature flags and variations
IsFeatureActive() / IsFeatureActiveWithTracking()
- 📨 Sends Tracking Data to Kameleoon (depending on the
trackparameter)
GetVariation method.
It takes a visitorCode and featureKey as mandatory arguments to check if the feature flag is active for a given user.
If the user has not been associated with your feature flag before, the SDK returns a random boolean value (true if the user should have this feature or false if not). However, if the user has already been registered with this feature flag, the SDK detects the previous feature flag value.
It is important to set up proper error handling in your code to catch any potential exceptions that may occur, as shown in the code example.
visitorCode, the IsFeatureActive method uses it as the unique visitor identifier, which is useful for cross-device experimentation. When you specify a visitorCode and set the isUniqueIdentifier parameter to true, the SDK links the flushed data with the visitor associated with the specified identifier.
The parameter
isUniqueIdentifier is deprecated. Please use UniqueIdentifier instead.The isUniqueIdentifier can be helpful in unique situations; for example, if you cannot access the anonymous visitorCode given to a visitor, but you can use an internal ID linked to that visitor through session merging.Kameleoon uses tracking to count sessions and visitors when you call certain methods, such as
IsFeatureActive(), GetVariation() or GetVariations().Use the default true value for the GetVariationOptParams.Track parameter when you expose visitors to a variation and need to count them. Set the GetVariationOptParams.Track parameter to false only if you call these methods before you expose visitors.For example, if you call GetVariations() to retrieve all variations before you expose visitors, set the GetVariationsOptParams.Track parameter to false. This setting prevents Kameleoon from prematurely counting a session. You can then trigger tracking later when you explicitly expose the visitor.Kameleoon sends tracking data every second by default. You can configure this interval up to five seconds using the tracking interval configuration option. Kameleoon groups tracking events into a single session as long as the interval between events is less than 30 minutes. If more than 30 minutes elapse between tracking events, Kameleoon counts the events as separate sessions. A visit appears in your reports 30 minutes after the last recorded event in the session.Parameters
Return value
Exceptions thrown
GetVariation()
- 📨 Sends Tracking Data to Kameleoon (depending on the
GetVariationOptParams.Trackparameter)
Variation assigned to a given visitor for a specific feature flag.
This method takes a visitorCode and featureKey as mandatory arguments. The GetVariationOptParams.Track argument is optional and defaults to true.
It returns the assigned Variation for the visitor. If the visitor is not associated with any feature flag rules, the method returns the default Variation for the given feature flag.
Ensure that proper error handling is implemented in your code to manage potential exceptions.
The default variation refers to the variation assigned to a visitor when they do not match any predefined delivery rules for a feature flag. In other words, it is the fallback variation applied to all users who are not targeted by specific rules. It’s represented as the variation in the “Then, for everyone else…” section in a management interface.
Parameters
Return value
Exceptions thrown
GetVariations()
- 📨 Sends Tracking Data to Kameleoon (depending on the
GetVariationsOptParams.Trackparameter)
Variation objects assigned to a given visitor across all feature flags.
This method iterates over all available feature flags and returns the assigned Variation for each flag associated with the specified visitor. It takes visitorCode as a mandatory argument, while GetVariationsOptParams.OnlyActive and GetVariationsOptParams.Track are optional.
- If
GetVariationsOptParams.OnlyActiveis set totrue, the methodGetVariations()will return feature flags variations provided the user is not bucketed with theoffvariation. - The
GetVariationsOptParams.Trackparameter controls whether or not the method will track the variation assignments. By default, it is set totrue. If set tofalse, the tracking will be disabled.
Variation as values. If no variation is assigned for a feature flag, the method returns the default Variation for that flag.
Proper error handling should be implemented to manage potential exceptions.
The default variation refers to the variation assigned to a visitor when they do not match any predefined delivery rules for a feature flag. In other words, it is the fallback variation applied to all users who are not targeted by specific rules. It’s represented as the variation in the “Then, for everyone else…” section in a management interface.
Parameters
Return value
Exceptions thrown
Parameters
Return value
Exceptions thrown
SetForcedVariation()
The method allows you to programmatically assign a specificVariation to a user, bypassing the standard evaluation process. This is especially valuable for controlled experiments where the usual evaluation logic is not required or must be skipped. It can also be helpful in scenarios like debugging or custom testing.
When a forced variation is set, it overrides Kameleoon’s real-time evaluation logic. Processes like segmentation, targeting conditions, and algorithmic calculations are skipped. To preserve segmentation and targeting conditions during an experiment, set SetForcedVariationOptParams.ForceTargeting=false instead.
Simulated variations always take precedence in the execution order. If a simulated variation calculation is triggered, it will be fully processed and completed first.
Parameters
Exceptions thrown
EvaluateAudiences()
- 📨 Sends Tracking Data to Kameleoon
EvaluateAudiences() should be called after all relevant visitor data has been set or updated, and just before getting a feature variation or checking a feature flag. This approach ensures that the visitor is evaluated against the most current data available, allowing for accurate audience assignment based on all criteria.
After calling this method, you can perform a detailed analysis of segment performance in Audiences Explorer.
Parameters
Exceptions thrown
GetDataFile()
Returns the current SDK configuration as aDataFile object.
Return value
Visitor data
GetVisitorCode()
This method was previously called
ObtainVisitorCode, which was removed in SDK version 3.0.0.GetVisitorCode() method to obtain the Kameleoon visitorCode for the current visitor. Here’s how it works:
- Kameleoon checks if there is a kameleoonVisitorCode cookie associated with the current HTTP request. If found, Kameleoon this code as the visitor identifier.
- If no cookie is found, the method will either randomly generate a new identifier, or use the defaultVisitorCode argument if it is passed. Using your identifiers as visitor codes allows you to match Kameleoon visitors with your own users without additional look-ups.
- The server-side kameleoonVisitorCode cookie is then set with the identifier value via HTTP header and the method returns the identifier value.
If you decide to provide your own
User ID instead of using the Kameleoon generated visitorCode, it is your responsibility to ensure that the User ID is unique. The SDK does not check for uniqueness. It’s important to note that the User ID you provide must not exceed 255 characters, as any excess characters will result in an exception being thrown.The
GetVisitorCode() method allows you to set simulated variations for a visitor. When cookies (from a request or document) contain the key kameleoonSimulationFFData, the standard evaluation process is bypassed. Instead, the method directly returns a Variation based on the provided data.You can apply simulations in two ways:- Automatically (recommended): If using Kameleoon Web Experimentation or the SDK in Hybrid mode, the cookie is created automatically when simulating a variant’s display using the Simulation Panel.
- Manually: Set the
kameleoonSimulationFFDatacookie manually.
- Simulated variations: Affect the overall feature flag result.
- Forced variations: Are specific to an individual experiment.
kameleoonSimulationFFData cookie follows this format:kameleoonSimulationFFData={"featureKey":{"expId":10,"varId":20}}: Simulates the variation withvarIdof experimentexpIdfor the givenfeatureKey.kameleoonSimulationFFData={"featureKey":{"expId":0}}: Simulates the default variation (defined in the Then, for everyone else in Production, serve section) for the givenfeatureKey.
encodeURIComponent.Parameters
Return value
Exceptions thrown
AddData()
TheAddData() method adds targeting data to storage so other methods can use the data to decide whether or not to target the current visitor.
The AddData() method does not return any value and does not interact with Kameleoon back-end servers on its own. Instead, all the declared data is saved for future transmission using the Flush*() method. This approach reduces the number of server calls made, as the data is typically grouped into a single server call that is triggered by the Flush*().
The TrackConversion() method also sends out any previously associated data, just like the Flush*(). The same holds true for GetVariation() and GetVariations() methods if an experimentation rule is triggered.
Parameters
Exceptions
FlushAll() / FlushVisitor() / FlushVisitorInstantly()
- 📨 Sends Tracking Data to Kameleoon
FlushAll()/FlushVisitor()/FlushVisitorInstantly() methods collects the Kameleoon data linked to the visitor. It then sends a tracking request, along with all data added using the AddData method, which has not yet been sent using one of these methods. Flush*() is non-blocking as the server call is made asynchronously.
Flush*() lets you control when the data associated with a given visitorCode is sent to our servers. For instance, if you call AddData() a dozen times, it would be inefficient to send data to the server after each time AddData() is invoked, so all you have to do is call Flush() once at the end.
The FlushVisitor()/FlushVisitorInstantly() method uses visitorCode as the unique visitor identifier, which is useful for cross-device experimentation. When you specify a visitorCode and set the isUniqueIdentifier parameter to true, the SDK links the flushed data with the visitor associated with the specified identifier.
The parameter
isUniqueIdentifier is deprecated. Please use UniqueIdentifier instead.The isUniqueIdentifier can be helpful in unique situations; for example, if you cannot access the anonymous visitorCode given to a visitor, but you can use an internal ID linked to that visitor through session merging.Parameters
Exceptions thrown
GetRemoteData()
TheGetRemoteData() method retrieves external data stored on Kameleoon’s remote server for the specified siteCode (specified in KameleoonClient constructor) according to a key passed as an argument. This key is typically the Kameleoon Visitor Code or your User ID.
You can use this method to retrieve user preferences, historical data, or any other data relevant to your application’s logic. By storing this data on our highly scalable servers using our Data API, you can efficiently manage massive amounts of data and retrieve it for all of your visitors or users.
The return value of the method is a JSON object that can be decoded using the json.Unmarshal() function. You can use this data to build advanced targeting segments for feature flags and experiments, or filter experiment and personalization reports based on any value stored in the retrieved data.
Note that, since a server call is required, this mechanism is asynchronous.
Parameters
Return value
Exceptions thrown
GetRemoteVisitorData()
GetRemoteVisitorData() is an asynchronous method for retrieving Kameleoon Visits Data for the VisitorCode from the Kameleoon Data API. The method adds the data to storage for other methods to use when making targeting decisions.
Data obtained using this method plays an important role when you want to:
- use data collected from other devices.
- access a user’s history, such as previously visited pages during past visits.
- use data that is only accessible on the client-side, like datalayer variables and goals that only convert on the front-end.
The parameter
IsUniqueIdentifier is deprecated. Please use UniqueIdentifier instead.The isUniqueIdentifier can be helpful in unique situations; for example, if you cannot access the anonymous visitorCode given to a visitor, but you can use an internal ID linked to that visitor through session merging.Parameters of GetRemoteVisitorData
Parameters of GetRemoteVisitorDataWithFilter
Parameters of GetRemoteVisitorDataWithOptParams
The
GetRemoteVisitorDataWithOptParams method is deprecated. Please use GetRemoteVisitorDataWithFilter and UniqueIdentifier. instead.Here is the list of
kameleoon.RemoteVisitorDataOptParams fields:The default value of
kameleoon.RemoteVisitorDataOptParams which is types.RemoteVisitorDataFilter{PreviousVisitAmount: 1, CurrentVisit: true, CustomData: true}, can be gotten with types.DefaultRemoteVisitorDataFilter() function.Return value
Using parameters in GetRemoteVisitorData()
TheGetRemoteVisitorData() method offers flexibility by allowing you to define various parameters when retrieving data on visitors. Whether you’re targeting based on goals, experiments, or variations, the same approach applies across all data types.
For example, let’s say you want to retrieve data on visitors who completed a goal “Order transaction”. You can specify parameters within the GetRemoteVisitorData() method to refine your targeting. For instance, if you want to target only users who converted on the goal in their last five visits, you can set the PreviousVisitAmount parameter to 5 and Conversions to true.
The flexibility shown in this example is not limited to goal data. You can use parameters within the GetRemoteVisitorData() method to retrieve data on a variety of visitor behaviors.
Here is the list of available
types.RemoteVisitorDataFilter options:GetVisitorWarehouseAudience()
Retrieves all audience data associated with the visitor in your data warehouse using the specifiedVisitorCode and WarehouseKey. The WarehouseKey is typically your internal user ID. The CustomDataIndex parameter corresponds to the Kameleoon custom data that Kameleoon uses to target your visitors. You can refer to the warehouse targeting documentation for additional details. The method returns a CustomData object, confirming that the data has been added to the visitor and is available for targeting purposes.
Parameters of GetVisitorWarehouseAudience
Parameters of GetVisitorWarehouseAudienceWithOptParams
Here is the list of
kameleoon.VisitorWarehouseAudienceOptParams fields:For
GetVisitorWarehouseAudience method parameters are passed into the function as params of struct VisitorWarehouseAudienceParams to make some of them optional (WarehouseKey and Timeout).For GetVisitorWarehouseAudienceWithOptParams method only optional parameters are passed into the function as params of struct VisitorWarehouseAudienceOptParams.Return value
SetLegalConsent()
You must use this method to specify whether the visitor has given legal consent to use personal data. Setting thelegalConsent parameter to false limits the types of data that you can include in tracking requests. This method helps you adhere to legal and regulatory requirements while responsibly managing visitor data. You can find more information on personal data in the consent management policy.
Parameters
Exceptions thrown
Consent revocation behavior
When you callSetLegalConsent() with consent=false, the SDK does not delete the kameleoonVisitorCode cookie. Instead, it stops extending the cookie’s expiration date, allowing the cookie to persist until it naturally expires.
If your compliance requirements demand the immediate removal of the cookie file upon opt-out, you must delete it manually using your framework’s native cookie management methods. The SDK will not remove the file automatically.
Goals and third-party analytics
TrackConversion()
- 📨 Sends Tracking Data to Kameleoon
visitorCode and goalId. In addition, this method also accepts an optional TrackConversionOptParams.Revenue, TrackConversionOptParams.Negative and TrackConversionOptParams.Metadata arguments. The visitorCode is usually identical to the one that was used when triggering the experiment.
The TrackConversion() method doesn’t return any value. This method is non-blocking as the server call is made asynchronously.
The parameter
isUniqueIdentifier is deprecated. Please use UniqueIdentifier instead.The isUniqueIdentifier can also be useful in other edge-case scenarios, such as when you can’t access the anonymous visitorCode that was originally assigned to the visitor, but you do have access to an internal ID that is connected to the anonymous visitor using session merging capabilities.Parameters
TrackConversionOptParams.Metadata values are accessible through raw data exports and the results page.If the
TrackConversionOptParams.Metadata parameter is provided, Kameleoon will use these specified values for the current conversion instead of what was previously collected using the AddData() method. If the parameter is omitted, Kameleoon will use the last tracked values for those CustomData prior to the conversion and within the same visit.Kameleoon will only consider the metadata values that are explicitly passed as parameters to the TrackConversion() method.In the example below, Kameleoon will associate the conversion only with the custom data value explicitly provided as a parameter (here: index 5 with the value ‘Amex Credit Card’).Exceptions
GetEngineTrackingCode()
Kameleoon integrates with several analytics solutions, including Mixpanel, Google Analytics 4, and Segment. To track server-side experiments correctly, call theGetEngineTrackingCode() method after the visitor triggers an experiment. The SDK returns JavaScript queue commands for the experiments that the visitor triggered during the previous five seconds. When you insert this code into the page, Engine.js processes the commands and sends the exposure events through the active analytics integration.
Refer to hybrid experimentation for more information on implementing this method.
- To use this feature, implement both the Go SDK and Kameleoon Engine.js. Because Engine.js is used only for tracking in this flow, you can install the asynchronous tag before the closing
</body>tag. - If you only want to track experiments in Kameleoon and do not need to send exposure events to third-party analytics tools, use the JavaScript / TypeScript SDK. This option works well for serverless edge compute platforms. The JavaScript / TypeScript SDK automatically tracks variations when you call
getVisitorCode, as long as you add the corresponding experiment assignments towindow.kameleoonQueue. - You can insert the returned tracking code directly into an HTML
<script>tag.
123456 and 234567 are experiment IDs, and 7890 and 8901 are variation IDs. In your implementation, the SDK generates these values in the returned tracking code.Parameters
Return value
Events
OnUpdateConfiguration()
OnUpdateConfiguration method allows you to handle the event when configuration has updated data. It takes one input parameter, handler. The handler that will be called when the configuration is updated using a real-time configuration event.
Parameters
Data types
Browser
TheBrowser data set stored here can be used to filter experiment and personalization reports by any value associated with it.
Conversion
TheConversion data set stored here can be used to filter experiment and personalization reports by any goal associated with it.
Cookie
Cookie contains information about the cookie stored on the visitor’s device.
Geolocation
Geolocation contains the visitor’s geolocation details.
CustomData
CustomData allows any type of data to be easily associated with each visitor. It can then be used as a targeting condition in segments or as a filter/breakdown in experiment reports. To learn more about custom data, please refer to this article.
-
Each visitor is allowed only one
CustomDatafor each uniqueindex. Adding anotherCustomDatawith the sameindexwill replace the existing one. - The custom data ‘index’ can be found in the Custom Data dashboard under the “INDEX” column.
- To prevent the SDK from sending data with the selected index to Kameleoon servers for privacy reasons, enable the option: Use this data only locally for targeting purposes when creating custom data.
-
Adding a
CustomDatainstance created with a name when the SDK instance configuration is not up to date or the name is not registered, will result in the data being ignored.
Device
You can use device data to filter experiment or personalization reports by any associated value.NewDevice
OperatingSystem
OperatingSystem contains information about the operating system on the visitor’s device.
NewOperatingSystem
PageView
You can use pageview data to filter experiment or personalization reports by any associated value.The index or ID of the referrer can be found in your Kameleoon account. It is important to note that this index starts at 0. This means the first acquisition channel you create for a given site will be assigned 0 as its ID, not 1.
NewPageView
NewPageViewWithTitle
UserAgent
Server-side experiments are more likely to be affected by bot traffic than client-side experiments. Kameleoon uses the IAB/ABC International Spiders and Bots List to tackle this issue and recognize known bots and spiders. Kameleoon also uses theUserAgent field to filter out bots and other unwanted traffic that might distort your conversion metrics. For more details, see our help article on bot filtering.
If you use internal bots, we suggest that you pass the value curl/8.0 of the userAgent to exclude them from our analytics.
NewUserAgent
UniqueIdentifier
If you don’t addUniqueIdentifier for a visitor, visitorCode is used as the unique visitor identifier, which is useful for Cross-device experimentation. When you add UniqueIdentifier for a visitor, the SDK links the flushed data with the visitor associated with the specified identifier.
The isUniqueIdentifier can be helpful in unique situations; for example, if you cannot access the anonymous visitorCode given to a visitor, but you can use an internal ID linked to that visitor through session merging.
NewUniqueIdentifier
ApplicationVersion
ApplicationVersion represents the semantic version number of your application.
NewApplicationVersion
Returned Types
DataFile
TheDataFile contains the SDK configuration details.
It can be extended with additional information if required by clients. If you need more details, please contact your Customer Success Manager.
FeatureFlag
TheFeatureFlag represents a set of properties that define a feature flag itself — for example, its Variations, Rules, environment status, and other related details.
It can be extended with additional information if required by clients. If you need more details, please contact your Customer Success Manager.
Rule
TheRule represents a set of properties that define a rule itself — for example, its Variations.
It can be extended with additional information if required by clients. If you need more details, please contact your Customer Success Manager.
Variation
Variation contains information about the visitor’s assigned variation (or the default variation, if no specific assignment exists).
- The
Variationobject provides details about the assigned variation and its associated experiment, while theVariableobject contains specific details about each variable within a variation. - Ensure that your code handles the case where
VariationIDorExperimentIDmay benil, indicating a default variation. - The
Variablesmap might be empty if no variables are associated with the variation.
Variable
Variable contains information about a variable associated with the assigned variation.
Deprecated methods
GetFeatureVariationKey()
- 📨 Sends Tracking Data to Kameleoon
Use
GetVariation() instead.Don’t forget to handle potential exceptions with proper error handling in your code. See the example code for guidance.
visitorCode, the GetFeatureVariationKey method uses it as the unique visitor identifier, which is useful for cross-device experimentation. When you specify a visitorCode and set the isUniqueIdentifier parameter to true, the SDK links the flushed data with the visitor associated with the specified identifier.
The parameter
isUniqueIdentifier is deprecated. Please use UniqueIdentifier instead.The isUniqueIdentifier can be helpful in unique situations; for example, if you cannot access the anonymous visitorCode given to a visitor, but you can use an internal ID linked to that visitor through session merging.Parameters
Return value
Exceptions thrown
GetActiveFeatureListForVisitor()
Use
GetActiveFeatures() instead.GetActiveFeatureListForVisitor() method takes a visitorCode parameter. When you call this method with a specific visitorCode, the method returns a list of feature flag keys that are available for that visitorCode.
Don’t forget to handle potential exceptions with proper error handling in your code. For example, see the following code:
Arguments
Return value
Exceptions thrown
GetActiveFeatures()
Use
GetVariations() instead.GetActiveFeatures() method retrieves information about the active feature flags that are available for the specified visitor code.
Don’t forget to handle potential exceptions with proper error handling in your code. For example, see the following code:
Arguments
Return value
Exceptions thrown
GetFeatureVariable()
- 📨 Sends Tracking Data to Kameleoon
Use
GetVariation() instead.GetFeatureVariable() method of our SDK.
This method takes a visitorCode, featureKey and variableKey as mandatory arguments to get a variable of the variation key for a given user.
If the user has never been associated with the feature flag, the SDK returns a variable value of the variation key randomly, following the feature flag rules. If the user is already registered with the feature flag, the SDK detects the previous variation key value and returns the variable value. If the user doesn’t match any of the rules, the default value will be returned.
Don’t forget to handle potential exceptions with proper error handling in your code. See the example code for guidance.
The parameter
isUniqueIdentifier is deprecated. Please use UniqueIdentifier instead.The isUniqueIdentifier can be helpful in unique situations; for example, if you cannot access the anonymous visitorCode given to a visitor, but you can use an internal ID linked to that visitor through session merging.Parameters
Return value
Exceptions thrown
GetFeatureVariationVariables()
Use
GetVariation() instead.GetFeatureVariationVariables method. This method requires two mandatory arguments: featureKey and variationKey. The method returns the data with the object type, as defined in the Kameleoon Platform.
Don’t forget to handle potential exceptions with proper error handling in your code. Check out the example code for guidance.