Skip to main content

Use visit history for targeting

This documentation explains how to retrieve and use visit history data in server-side experiments and feature flags. Using the Data API Visit endpoint combined with the custom data feature, you can easily target users based on their visit history and other relevant data (including more than 30 different data points) collected by Kameleoon in real time. By following the steps in this guide, you can retrieve data points such as visit history, browser information, device type, and more from the Kameleoon Data API endpoint and use that data as targeting criteria in your feature flags or experiments.

To use this feature, you need to implement hybrid experimentation. We recommend implementing both an SDK and a Kameleoon JavaScript tag. You can implement the Kameleoon Asynchronous tag. You can install the tag just before your closing </body> tag in your HTML page, as it will be only used for data collection purposes.


This is a premium feature that requires an add-on (remote sync of data or cross-device history reconciliation) with an additional usage fee. To access this feature, contact your Customer Success Manager for pricing and licensing options.

By following these simple steps, you can retrieve and use data in your server-side experiments and feature flags. This allows you to create more targeted and personalized experiences for your users based on their visit history and other relevant data.

Create custom data

To use client-side data as a targeting criterion, you first need to create a custom data entry for the data point, following these steps.

  1. In the Kameleoon app, open the Configure > Advanced tools page:
  2. In the Custom data section, click +New.
  3. Give your custom data a name (for example, "Number of visits".)
  4. For the acquisition method, choose Kameleoon SDK method
  5. For the type, select Single
  6. For the data format, select Number.
  7. Click Next and Skip the following screen to save the custom data.

Retrieve data from the Data API Visit endpoint

Once you've created the custom data, you need to retrieve the relevant data from the Data API endpoint. Here's how to do it:

  1. In your app, call the Data API Visit endpoint as shown in the following Go code. In url parameter, replace SITECODE and USERID with your project site code and the user ID, respectively. The following example code shows how to retrieve the staticData object collected by Kameleoon (which contains device information, number of visits, and more):
package main

import (

func main() {

url := ""
method := "GET"

client := &http.Client {
req, err := http.NewRequest(method, url, nil)

if err != nil {
res, err := client.Do(req)
if err != nil {
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
  1. When your app calls the Data API Visit endpoint, the server will respond with a JSON object containing client-side data related to the current visit, including the number of visits. The 'visitNumber' field in the 'data' object represents the number of times the user has visited the website. You can parse this JSON response to retrieve the 'visitNumber' value in your source code.
"currentVisit": {
"siteCode": "kqfwz0rys3",
"visitorCode": "jilrlpwoo9xkuhtb",
"staticDataEvent": {
"itp": false,
"time": 1682071499308,
"data": {
"visitNumber": 2,
"timeSincePreviousVisit": 7455637,
"firstReferrerHref": null,
"browser": "Chrome",
"browserIndex": 0,
"browserVersion": 112,
"os": "Mac",
"osIndex": 1,
"windowWidth": 1440,
"windowHeight": 738,
"screenWidth": 1440,
"screenHeight": 900,
"timeZoneId": "Europe/Paris",
"localeLanguageTag": "en-GB",
"deviceType": "DESKTOP",
"mappingIdentifier": null,
"experimentIdToInfluence": {},
"personalizationIdToInfluence": {}
"previousVisits": []

Retreving data for the current visit is a premium option. For more information, contact your Customer Success Manager.

Set the custom data value

Now that you have the value of the visitNumber variable, you can set it as the value of the Number of visits custom data entry using the SDK addData() method (for help, refer to the corresponding SDK documentation). Here's an example in Go:

Replace the ID with the custom data index which you can retrieve from the Kameleoon app:

client.AddData(visitorcode, &types.CustomData{
ID: "0",
Value: "visitNumber value", //which you get from the Data API endpoint response

Use the custom data as a targeting criterion

Finally, you can use the Number of visits custom data entry as a targeting criteria in your server-side experiments and feature flags. Here's how:

  1. In the Segments page (Configure > Segments), create a new segment or open an existing segment to open the segment builder.
  2. In the Custom Data* section, select the Number of visits** custom data as a targeting criterion.
  3. Set a target threshold or range, such as is higher than 5.
  4. Save your segment and use it in your experiments and feature flags.