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 asfalse
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 tofalse
if optional data is not pre-loaded. Note that if you don't pre-load the optional data usinggetRemoteVisitorData
, or you don't set the optionalshouldAddData
/addData
boolean parameter totrue
when callinggetRemoteVisitorData
, your app needs to calladdData
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.
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 type | Pre-loading required | Evaluation details | Associated SDK data |
---|---|---|---|
Exclusive Feature Flag | Optional | Exclude visitors exposed to a feature experiment | Internal data saved after some feature experiments were triggered |
Target Feature Flag | Optional | Select visitors based on feature experiments they're exposed to | Internal data saved after some feature experiments were triggered |
Browser | Optional | Select visitors based on browser type and version | Browser data |
Device | Optional | Select visitors based on device type | Device data |
Conversion | Optional | Select visitors based on the goal ID of a conversion | Conversion data |
Custom Data | Optional | Select visitors based on custom data | CustomData |
Page Title | Optional | Select visitors based on the title of the page | PageView data |
Page Url | Optional | Select visitors based on the URL of the page | PageView data |
SDK Language | N/A | Select visitors based on current SDK language or framework | The SDK in use |
Visitor Code | N/A | Select visitors based on their visitor code value | visitorCode passed as an argument to a method |
Browser Cookie | N/A | Select visitors based on a cookie key and value | Cookie data and browser cookie |
Operating System | Optional | Select visitors based on their operating system type | OperatingSystem data |
IP Geolocation | Optional | Select visitors based on their geolocation data | GeolocationData |
Segment | N/A | Select visitors based on whether they are targeted by certain segment | Internal segment configuration data |
Previous Page | Optional | Select visitors that previously visited page a URL | PageView data |
Number of Page Views | Optional | Select visitors based on number of pages visited | PageView data |
Time since First Visit | Required | Select visitors based on time elapsed since first visit | Visits data collected from Data API |
Time since Last Visit | Required | Select visitors based on time elapsed since last visit | Visits data collected from Data API |
Number of Visits Today | Required | Select visitors based on number of visits today | Visits data collected from Data API |
Total Number of Visits | Required | Select visitors based on total number of visits | Visits data collected from Data API |
New or Returning Visitors | Required | Select only visitors that are either new or returning | Visits 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.
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 type | Pre-loading required | Evaluation details | Associated SDK data | Supported SDKs |
---|---|---|---|---|
Browser | Optional | Select visitors based on browser type and version | Browser data | Java, C#, PHP, Ruby, Python, Go |
Device | Optional | Select visitors based on device type | Device data | All |
Conversion | Optional | Select visitors based on the goal ID of a conversion | Conversion data | All |
Custom Data | Optional | Select visitors based on custom data | CustomData | All |
Page Title | Optional | Select visitors based on the title of the page | PageView data | Java, C#, PHP, Ruby, Python, Go |
Page Url | Optional | Select visitors based on the URL of the page | PageView data | Java, C#, PHP, Ruby, Python, Go |
SDK Language | N/A | Select visitors based on current SDK language or framework | The SDK in use | All |
Visitor Code | N/A | Select visitors based on their visitor code value | visitorCode passed as an argument to a method | All |
AppVersion | N/A | Select visitors based on their application version. | ApplicationVersion data | Android 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.
- In the Kameleoon app, click Configure > Custom data.
- In the Custom data section, click New custom data.
- Choose the project.
- Enter a descriptive name for your custom data.
- For the acquisition method, choose Kameleoon SDK method
- For the type, select Single
- For the data format, select Number.
- Choose the appropriate scope for the data.
- 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:
- In your app, call the Data API Visit endpoint as shown in the following Go code. In the
url
parameter, replaceSITECODE
andUSERID
with your project site code and the user ID, respectively. The following example code shows how to retrieve thestaticData
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¤tVisit=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))
}
- 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:
- In the Segments page (Configure > Segments), create a new segment or open an existing segment to open the segment builder.
- In the Custom Data* section, select the Number of visits** custom data as a targeting criterion.
- Set a target threshold or range, such as is higher than 5.
- Save your segment and use it in your experiments and feature flags.