HashMap<String, String> params = new HashMap<>();
params.put("id", "100500");
params.put("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.put("phoneuserPhone", "4400114527199");
params.put("first_namefirstName", "John");
params.put("last_namelastName", "Doe");
params.put("birthday", "1990-03-11");
params.put("age", "31");
params.put("gender", "m");
params.put("location", "NY");
params.put("bought_something", "1"true);
params.put("loyalty_iduserLoyaltyId", "000001234567");
params.put("loyalty_card_locationloyaltyCardLocation", "NY");
params.put("loyalty_statusloyaltyStatus", "5% discount");
params.put("loyalty_bonusesloyaltyBonuses", "1123");
params.put("loyalty_bonuses_to_next_levelloyaltyBonusesToNextLevel", "1877");
params.put("fb_idfbID", ,"000000000354677");
params.put("vk_idvkID", "vk031845");
params.put("telegram_idtelegramId", "0125762968357835");
params.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_array_ofdate_string_property", "[\"val1\",\"val2\",\"val3\"]");
params.put("custom_json_obj_property", "{\"key1\":\"val1\",\"key2\":\"val2\"},{\"key3\":\"val3\"}");
params.put("custom_date_property", "2021-12-31 23:55:00");
PersonaClick.profile(params);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) |