Each authenticated profile includes an optional demographic which can be used to increase the accuracy of any analysis. This data is not collected automatically. Your app can choose to GET or POST this demographic via the Sahha API.
Data Format
All values are optional
Leave out any value you don't have.
gender : String
Gender must be a valid String from this list:
'Male''Female''Gender Diverse'
Sahha ignores any other value. Use the values exactly as shown: Android SDK versions up to 1.4.0 also ignore any other letter case, such as 'male'.
birthDate : String
Birth Date must be a String in the format 'YYYY-MM-DD'. For example, '1990-05-20'. Send the date only, without a time.
The Sahha API also accepts age, but the SDKs don't send it.
Using the API for Demographics
You can GET or POST demographic info via the API using this model.
Which fields each SDK sends
Every SDK and plugin sends only gender and birthDate. The Android SDK's SahhaDemographic also has age, country and nine other properties, but the SDK doesn't send them, so they're never stored. The plugins ignore any other keys you pass.
// All values are optional
public struct SahhaDemographic: Codable, Equatable, Sendable {
public var gender: String? // "Male", "Female" or "Gender Diverse"
public var birthDate: String? // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
} // All values are optional
data class SahhaDemographic(
val gender: String? = null, // "Male", "Female" or "Gender Diverse"
val birthDate: String? = null, // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
)
// The class also has age, country and nine other properties. The SDK doesn't send them. // All values are optional
var demographic = {
"gender" : "Female", // string, "Male", "Female", "Gender Diverse"
"birthDate" : "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}; // All values are optional
const demographic = {
gender: 'Female', // string, "Male", "Female", "Gender Diverse"
birthDate: '1990-05-20' // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}; // All values are optional
export interface SahhaDemographic {
age?: number; // ignored: not sent to Sahha
gender?: string; // string, "Male", "Female", "Gender Diverse"
birthDate?: string; // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
} POST
An example POST of demographic info via the SDK.
let demographic = SahhaDemographic(
gender: "Female",
birthDate: "1990-05-20"
)
Sahha.postDemographic(demographic) { error, success in
if let error = error {
print(error)
}
print(success)
} val demographic = SahhaDemographic(
gender = "Female",
birthDate = "1990-05-20"
)
Sahha.postDemographic(demographic) { error, success ->
if (error != null) {
println(error)
} else {
println(success.toString())
}
} var demographic = {
"gender" : "Female", // string, "Male", "Female", "Gender Diverse"
"birthDate" : "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
};
SahhaFlutter.postDemographic(demographic)
.then((success) {
debugPrint(success.toString());
})
.catchError((error, stackTrace) {
debugPrint(error.toString());
}); const demographic = {
gender: "Female", // string, "Male", "Female", "Gender Diverse"
birthDate: "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
Sahha.postDemographic(demographic, (error: string, success: boolean) => {
if (error) {
console.error(`Error: ${error}`);
} else if (success) {
console.log(`Success: ${success}`);
}
}); Sahha.postDemographic({
demographic: {
gender: 'Female',
birthDate: '1990-05-20'
}
}).then(
function (response) {
console.log(response.success);
},
function (error) {
console.log(error);
}
); GET
An example GET of demographic info via the SDK.
Sahha.getDemographic() { error, demographic in
if let error = error {
print(error)
}
if let demographic = demographic {
print(demographic)
}
} Sahha.getDemographic() { error, demographic ->
if (error != null) {
println(error)
} else if (demographic != null) {
println(demographic)
}
} SahhaFlutter.getDemographic()
.then((value) {
debugPrint(value);
})
.catchError((error, stackTrace) {
debugPrint(error.toString());
}); Sahha.getDemographic((error: string, value?: string) => {
if (error) {
console.error(`Error: ${error}`);
} else if (value) {
console.log(`Value: ${value}`);
}
}); Sahha.getDemographic().then(
function (response) {
console.log(response.demographic);
if (response.demographic) {
const json = JSON.parse(response.demographic);
}
},
function (error) {
console.log(error);
}
);