Skip to main content

Use visit history to target users

Using hybrid mode allows you to target users based on more than 20 predefined targeting conditions available in Kameleoon. To use all of the predefined targeting conditions, you must implement Kameleoon in hybrid mode by implementing both the SDK and the Kameleoon JavaScript tag. We recommend installing the Kameleoon Asynchronous tag in a Tag Management System (TMS) or just before your closing </body> tag in your HTML page. The tag is used only for data collection purposes.

Alternatively, you can use the Data API Visit endpoint with the custom data feature to target users based on other relevant data (including more than 30 different data points) collected by Kameleoon in real time. See the Using the Data API endpoint in the SDKs for additional targeting criteria section below for details.

Use predefined targeting conditions

The Kameleoon SDKs support a variety of predefined targeting conditions that you can use to target users in your campaigns. The list of predefined targeting conditions that are available to your app depends on which SDK you are using. Some targeting conditions require that your app has pre-loaded the targeting data before using the condition.

Pre-load your targeting data

Since the SDK runs on the client hardware for a shorter period and minimizes the use of network calls, the SDK limits the amount of data it provides. However, your app can call the getRemoteVisitorData method (or equivalent in your SDK) to retrieve all of the data that the Kameleoon application file collects on the front end for the current visitor. This provides the SDK with access to all of the targeting data for targeting purposes. Some of the data must be pre-loaded in order for your targeting conditions to work, while others are considered optional. The Pre-loading required column in the following tables indicates one of the following remote data requirements:

  • Required: If your app has not pre-loaded a Required data field using the asynchronous getRemoteVisitorData method, Kameleoon automatically resolves the entire targeting condition as false and the user won't be included under the targeting condition even if they are in other target segments.
  • Optional: If your app has not pre-loaded an Optional data field, the SDK evaluates the targeting condition normally using all of the other segments configured in your target. In other words, using getRemoteVisitorData can increase the range of data available for evaluation, but the targeting condition does not automatically resolve to false if optional data is not pre-loaded. Note that if you don't pre-load the optional data using getRemoteVisitorData, or you don't set the optional shouldAddData/addData boolean parameter to true when calling getRemoteVisitorData, your app needs to call addData to explicitly set the value of the data field for the current visitor before you can use the data in the Segment Builder.
  • N/A: Not Applicable. The condition doesn't rely on remote data. Instead, it's evaluated based on data collected natively by the SDK.

Predefined targeting conditions

The complete list of pre-defined targeting conditions is only available in the following SDKS:

  • NodeJS SDK
  • JavaScript/TypeScript SDK
  • React SDK
  • C# SDK

For other SDKs, see the next section Predefined targeting conditions for all other SDKs.

Additionally, if you are not using hybrid mode (that is, you are using an SDK, but not the Kameleoon JavaScript tag), you don't have access to the full list of targeting conditions, even if you are using one of the SDKs above. In this case, you have access to Predefined targeting conditions for all other SDKs.

caution

Before you can use the data for targeting in the Segment Builder, your app must call addData() to set the value of the corresponding data field for a specific visitor. The SDK calls addData() automatically whenever you call getRemoteVisitorData(), as long as you don't set the optional shouldAddData/addData parameter to false (the default value is true). Otherwise, you can call the addData() method manually to set the value of each required data field for the visitor. See the documentation for your chosen SDK for more information on these methods.

The supported SDKs above have access to all of the following conditions:

Condition typePre-loading requiredEvaluation detailsAssociated SDK data
Exclusive Feature FlagOptionalExclude visitors exposed to a feature experimentInternal data saved after some feature experiments were triggered
Target Feature FlagOptionalSelect visitors based on feature experiments they're exposed toInternal data saved after some feature experiments were triggered
BrowserOptionalSelect visitors based on browser type and versionBrowser data
DeviceOptionalSelect visitors based on device typeDevice data
ConversionOptionalSelect visitors based on the goal ID of a conversionConversion data
Custom DataOptionalSelect visitors based on custom dataCustomData
Page TitleOptionalSelect visitors based on the title of the pagePageView data
Page UrlOptionalSelect visitors based on the URL of the pagePageView data
SDK LanguageN/ASelect visitors based on current SDK language or frameworkThe SDK in use
Visitor CodeN/ASelect visitors based on their visitor code valuevisitorCode passed as an argument to a method
Browser CookieN/ASelect visitors based on a cookie key and valueCookie data and browser cookie
Operating SystemOptionalSelect visitors based on their operating system typeOperatingSystem data
IP GeolocationOptionalSelect visitors based on their geolocation dataGeolocationData
SegmentN/ASelect visitors based on whether they are targeted by certain segmentInternal segment configuration data
Previous PageOptionalSelect visitors that previously visited page a URLPageView data
Number of Page ViewsOptionalSelect visitors based on number of pages visitedPageView data
Time since First VisitRequiredSelect visitors based on time elapsed since first visitVisits data collected from Data API
Time since Last VisitRequiredSelect visitors based on time elapsed since last visitVisits data collected from Data API
Number of Visits TodayRequiredSelect visitors based on number of visits todayVisits data collected from Data API
Total Number of VisitsRequiredSelect visitors based on total number of visitsVisits data collected from Data API
New or Returning VisitorsRequiredSelect only visitors that are either new or returningVisits data collected from Data API

Predefined targeting conditions for all other SDKs

SDKs that don't support the full list of targeting conditions, or that don't use hybrid mode, still have access to a limited set of targeting conditions.

If you're not using hybrid mode, you can call addData() to add Kameleoon data types to the Kameleoon platform so that you can pre-load the data in subsequent visits.

caution

Before you can use the data for targeting in the Segment Builder, your app must call the addData() method to set the value of the corresponding data field for a specific visitor. The SDK calls addData() automatically whenever you call getRemoteVisitorData(), as long as you don't set the optional shouldAddData/addData parameter to false (the default value is true). Otherwise, you can call the addData() method manually to set the value of each required data field for the visitor. See the documentation for your chosen SDK for more information on these methods.

See the supported SDK column to see which conditions are supported in your SDK:

Condition typePre-loading requiredEvaluation detailsAssociated SDK dataSupported SDKs
BrowserOptionalSelect visitors based on browser type and versionBrowser dataJava, C#, PHP, Ruby, Python, Go
DeviceOptionalSelect visitors based on device typeDevice dataAll
ConversionOptionalSelect visitors based on the goal ID of a conversionConversion dataAll
Custom DataOptionalSelect visitors based on custom dataCustomDataAll
Page TitleOptionalSelect visitors based on the title of the pagePageView dataJava, C#, PHP, Ruby, Python, Go
Page UrlOptionalSelect visitors based on the URL of the pagePageView dataJava, C#, PHP, Ruby, Python, Go
SDK LanguageN/ASelect visitors based on current SDK language or frameworkThe SDK in useAll
Visitor CodeN/ASelect visitors based on their visitor code valuevisitorCode passed as an argument to a methodAll
AppVersionN/ASelect visitors based on their application version.ApplicationVersion dataAndroid SDK, iOS SDK, React Native SDK, Flutter SDK

Using the Data API endpoint in the SDKs for additional targeting criteria

This section explains an example implementation that demonstrates the steps you need to follow to retrieve and use additional data in your feature flags and experiments. 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, click Configure > Custom data.
  2. In the Custom data section, click New custom data.
  3. Choose the project.
  4. Enter a descriptive name for your custom data.
  5. For the acquisition method, choose Kameleoon SDK method
  6. For the type, select Single
  7. For the data format, select Number.
  8. Choose the appropriate scope for the data.
  9. 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 the 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 (
"fmt"
"net/http"
"io/ioutil"
)

func main() {

url := "https://data.kameleoon.io/visit/visitor?siteCode=SITECODE&currentVisit=true&visitorCode=USERID&staticData=true"
method := "GET"

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

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

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
  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": []
}

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", //Index of your custom data
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.