val params = HashMap<String, String>()
params["id"] = "100500"
params["email"] =/**
* Initializes arrays of basic data types.
* These arrays demonstrate that profile properties can support arrays of strings, integers, floats, booleans, and dates.
*/
val stringArray = arrayOf("item1", "item2", "item3")
val intArray = arrayOf(1, 2, 3, 4, 5)
val floatArray = arrayOf(1.1f, 2.2f, 3.3f)
val boolArray = arrayOf(true, false, true)
val dateArray = arrayOf(Date(), Date(), Date())
/**
* Creates a nested JSON object.
* This object demonstrates how to structure complex data with key-value pairs, including strings and integers.
*/
val nestedObject = JSONObject().apply {
put("nestedStringKey", "nestedValue")
put("nestedIntKey", 456)
}
/**
* Creates a custom JSON object.
* The object includes various data types such as strings, integers, floats, booleans, dates, arrays,
* and even another nested JSON object.
*/
val customObject = JSONObject().apply {
put("stringKey", "stringValue")
put("intKey", 123)
put("floatKey", 45.67f)
put("boolKey", true)
put("dateKey", Date())
put("arrayKey", JSONArray(arrayOf(1, 2, 3)))
put("nestedObjectKey", nestedObject)
}
/**
* Creates an array of custom JSON objects.
* This demonstrates how to pass an array of complex objects as a single profile property.
*/
val customObjectArray = arrayOf(customObject, customObject)
/**
* Builds the ProfileParams object using the Builder pattern.
* This example demonstrates how to add a wide range of user properties,
* including basic data types, arrays, and custom objects, to be passed to the SDK.
*/
val params = ProfileParams.Builder()
.put("userId", 100500)
.put("userEmail", "john.doe@examplemail.com")
params["phone"] = .put("userPhone", "4400114527199")
params["first_name"] =.put("firstName", "John")
params["last_name"] = .put("lastName", "Doe")
params[.put("birthday"], = "1990-03-11")
params[.put("age"], = "31"
params[)
.put("gender"] =, "m")
params[.put("location"] =, "NY")
params[.put("bought_something"], =true)
.put("1userLoyaltyId", params["loyalty_id"] = "000001234567")
params["loyalty_card_location"] =.put("loyaltyCardLocation", "NY")
params["loyalty_status"] = .put("loyaltyStatus", "5% discount")
params["loyalty_bonuses"] = "1123"
params["loyalty_bonuses_to_next_level"] = "1877"
params["fb_id"] = "000000000354677"
params["vk_id"] = "vk031845"
params["telegram_id"] = "0125762968357835"
params["kids"] = .put("loyaltyBonuses", 1123)
.put("loyaltyBonusesToNextLevel", 1877)
.put("fbID", "000000000354677")
.put("vkID", "vk031845")
.put("telegramId", "0125762968357835")
.put("kids", "[{\"gender\":\"m\",\"birthday\":\"2001-04-12\"},{\"gender\": \"f\", \"birthday\": \"2015-07-28\"}]")
params[.put("auto"], = "[{\"brand\":\"Nissan\",\"model\":\"Qashqai\",\"vds\":\"TM7N243E4G0BJG978\"}]")
params[.put("custom_string_property"] =, "string_value")
params[.put("custom_integer_property"], = "100500"
params[)
.put("custom_float_property"] =, "7.62"
params[)
.put("custom_arraydate_of_string_property"] = "[\"val1\",\"val2\",\"val3\"]"
params["custom_json_obj_property"] = "{\"key1\":\"val1\",\"key2\":\"val2\"},{\"key3\":\"val3\"}"
params["custom_date_property"] = "2021-12-31 23:55:00", "2021-12-31 23:55:00")
.put("stringArray", stringArray)
.put("intArray", intArray)
.put("floatArray", floatArray)
.put("boolArray", boolArray)
.put("dateArray", dateArray)
.put("customObject", customObject)
.put("customObjectArray", customObjectArray)
/**
* Calls the SDK's profile method to save user profile data.
* A callback is included to handle success or failure of the API call.
*/
sdk.profile(params); |