Skip to main content

Processing offline goal conversions in experiments

As previously explored, Kameleoon’s DATA API lets users fetch and write data to its servers. Three key endpoints facilitate this: Visit, Product Recommendation, and Map.

In some situations, you may want to send goal conversion events to Kameleoon that occurred offline, such as in-store transactions or over-the-phone transactions. The Visit endpoint, described in this tutorial, is specifically designed to post offline data for individual visitors.

In contrast to the MAP endpoint, which offers greater flexibility in the structure of submitted data, the Visit endpoint only allows for the submission of predefined data points. These include conversions, events, and page view events, along with several other types of data. This information can then be utilized in the experiment results to filter and analyze the data effectively.

This article will discuss the following operations:

  • Sending offline goal conversions using the POST/visit/events endpoint and,
  • Verifying the transmission of offline goal data from the previous step using the GET/visit/visitor endpoint

Sending offline goal conversion

To transmit offline conversion data to the Kameleoon server, you must send a POST request to the following URL that must include the siteCode and the visitorCode:

https://data.kameleoon.io/visit/events?siteCode=your_sitecode&visitorCode=visitor_code
note

The domain for your Kameleoon scripts may vary from one project to another. Depending on their creation date, your projects may be hosted on either kameleoon.eu or kameleoon.io. Ensure you use the domain displayed in your project in the Kameleoon App. If in North America, the domain in the URL will be na-data.kameleoon.io or na-data.kameleoon.eu.

  • This siteCode is a unique ID associated with the experiment project you will be working on. Instructions on retrieving it are available at this link.

  • The visitorCode is a unique string assigned to each user browsing your app. It is used to assign users to experiments and variants while tracking their data in our reporting system. For Kameleoon Web Experimentation, the visitor code is randomly generated and assigned to each user. In the case of Kameleoon Feature Experimentation, our Web SDK offers a method to generate the visitor code, or you can use your own ID, particularly if your website requires users to log in before accessing content.

note

If you use Kameleoon’s cross-device reconciliation, you can use the endpoint's mappingIdentifier parameter instead of the visitorCode. Read more here.

note

You can use this endpoint to perform bulk conversions for multiple visitorCodes. To do this, include each event in the request body.

These are the following mandatory parameters for the request body for sending goal data:

  • nonce: this is a random string of 16 hexadecimal characters unique to each event
  • eventType: string specifying the event type. For this example, it will be CONVERSION
  • goalID: unique ID of the goal. Please refer to this document to learn more about accessing and managing goals.
  • revenue: Optional float parameter indicating the revenue generated during this conversion.

Which will translate to the following cURL request:

curl -X POST 'https://data.kameleoon.io/visit/events?siteCode=f17c21u1ag&visitorCode=245fc' \
-H 'Content-Type: application/json' \
-H 'User-Agent: CustomUserAgent/1.0' \
-d '[{"nonce":"a2bb4d22083348ef","eventType":"CONVERSION","goalId":36151,"revenue":23.50}]'

Since no object or response is returned after a successful request, the next section will show how to confirm its success by sending a request to the GET/visit/visitor endpoint.

Verifying offline goal conversion data

In this step, we will use the GET endpoint to verify whether the POST request from the above section was successful. You will need to include the following in the request URL:

  • siteCode - Please refer to step 1 for the instructions on how to retrieve this code.
  • visitorCode - The same visitor code you retrieved in the previous section.
  • maxNumberPreviousVisits - Integer representing the maximum number of previous visits to return.
  • currentVisit - If focusing on the current visit, set this to true, otherwise the default value is false. (Note: This is only available to you if you use Kameleoon Feature Experimentation)
  • conversion - Set to true if you would want to get conversion events for the given user and for goals you have set in your Kameleoon account
note

If you do not have access to Feature Experimentation, you must wait until Kameleoon processes the visit, usually after 30 minutes of inactivity. The conversion data will then show up in the last computed previous visit.

This translates to the following cURL request:

curl -X GET 'https://data.kameleoon.io/visit/visitor?siteCode=f17c21u1ag&visitorCode=245fc&maxNumberPreviousVisits=5&currentVisit=true&conversion=true' \
-H 'Content-Type: application/json' \
-H 'User-Agent: CustomUserAgent/1.0' \

If your GET request has been processed successfully, you will receive a response with the data that was sent in the previous request, which confirms that the POST request in the previous section was also successful:

{
"previousVisits": [
{
"siteCode": "f17c21u1ag",
"visitorCode": "245fc",
"timeStarted": 1740447713028,
"conversionEvents": [
{
"itp": false,
"time": 1740447713028,
"data": {
"goalId": 361517,
"revenue": 23.50,
"negative": false,
"metadata": {}
}
}
]
}
]
}

Additional information

In most cases, when sending conversions for a given goal and visitor, you will want to use them in experiment reports. Kameleoon links conversions to experiments based on the following rules:

  • Conversions during active visits: If a conversion occurs while the visitor is still active on your website and has been targeted by the experiment, Kameleoon will link the conversion to the experiment for that visit.

  • Conversions after visits end: If a visitor was previously included in an experiment but later makes a purchase through a different channel, such as by phone or in a physical store, Kameleoon will still attribute that conversion to the experiment as long as it occurs within the defined attribution window (default: 7 days). In this situation, Kameleoon will create a new visit associated with the conversion.

To get a complete view of conversions, we recommend analyzing the data at the visitor level, as this will also include conversions that occurred during non-targeted visits—provided that the experiment previously targeted the visitor. To know more about how Kameleoon counts conversions, we recommend reading this documentation.