---
title: Demographics
---


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

{% callout title="All values are optional" %}

String values are case insensitive (for example: `'us'` and `'US'` are equal and valid).
{% /callout %}

#### `age : Int`

Age must be a valid `Int` between `1 - 99`.

#### `gender : String`

Gender must be a valid `String` from this list:

- `'male'`
- `'female'`
- `'gender diverse'`

#### `country : String`

Country must be a valid 2 character ISO `String` from this list:

[ISO Country Codes](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes)

#### `birthCountry : String`

Birth Country must be a valid 2 character ISO `String` from this list:

[ISO Country Codes](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes)

#### `ethnicity : String`

Any `String` value.

#### `occupation : String`

Any `String` value.

#### `industry : String`

Any `String` value.

#### `incomeRange : String`

Any `String` value.

#### `education : String`

Any `String` value.

#### `relationship : String`

Any `String` value.

#### `locale : String`

Any `String` value.

#### `livingArrangement : String`

Any `String` value.

#### `birthDate : String`

Birth Date must be a `String` in the format `'YYYY-MM-DD'`. For example, `'1990-05-20'`.

---

## Using the API for Demographics

You can `GET` or `POST` demographic info via the API using this model.

{% tabs %}

{% tab label="iOS" %}

```swift title=MyApp.swift
// All values are optional

public struct SahhaDemographic: Codable {
    public var age: Int?
    public var gender: String? // "male", "female", "gender diverse"
    public var country: String? // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var birthCountry: String?  // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var ethnicity: String? // any string
    public var occupation: String? // any string
    public var industry: String? // any string
    public var incomeRange: String? // any string
    public var education: String? // any string
    public var relationship: String? // any string
    public var locale: String? // any string
    public var livingArrangement: String? // any string
    public var birthDate: String? // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
```

{% /tab %}

{% tab label="Android" %}

```kotlin title=MainActivity.kt
// All values are optional

class SahhaDemographic {
    public var age: Int?
    public var gender: String? // "male", "female", "gender diverse"
    public var country: String? // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var birthCountry: String?  // ISO 2 character code, i.e. "us", "uk", "au", etc.
    public var ethnicity: String? // any string
    public var occupation: String? // any string
    public var industry: String? // any string
    public var incomeRange: String? // any string
    public var education: String? // any string
    public var relationship: String? // any string
    public var locale: String? // any string
    public var livingArrangement: String? // any string
    public var birthDate: String? // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
```

{% /tab %}

{% tab label="Flutter" %}

```dart title=MyApp.dart
// All values are optional

var demographic = {
  "age" : 35, // int
  "gender" : "Female", // string, "Male", "Female", "Gender Diverse"
  "country" : "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  "birthCountry" : "UK" // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  "birthDate" : "1990-05-20" // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
};
```

{% /tab %}

{% tab label="React Native" %}

```typescript title=MyApp.tsx
// All values are optional

const demographic = {
	age: 35, // number
	gender: 'Female', // string, "Male", "Female", "Gender Diverse",
	country: 'NZ', // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
	birthCountry: 'UK', // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
	birthDate: '1990-05-20' // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
};
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript title=MyApp.js
interface SahhaDemographic {
  age?: number; // number
  gender?: string; // string, "Male", "Female", "Gender Diverse",
  country?: string; // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry?: string; // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  ethnicity?: string;
  occupation?: string;
  industry?: string;
  incomeRange?: string;
  education?: string;
  relationship?: string;
  locale?: string;
  livingArrangement?: string;
  birthDate?: string; // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}
```

{% /tab %}

{% /tabs %}

---

## POST

An example `POST` of demographic info via the SDK.

{% tabs %}

{% tab label="iOS" %}

```swift title=MyApp.swift
let demographic = SahhaDemographic(
    age: 32,
    gender: "Female",
    country: "NZ",
    birthCountry: "UK",
    birthDate: "1990-05-20"
)

Sahha.postDemographic(demographic) { error, success in
    if let error = error {
        print(error)
    }
    print(success)
}
```

{% /tab %}

{% tab label="Android" %}

```kotlin title=MainActivity.kt
var demographic = SahhaDemographic(
    age: 32,
    gender: "Female",
    country: "NZ",
    birthCountry: "UK",
    birthDate: "1990-05-20"
)

Sahha.postDemographic(demographic) { error, success ->
    if (error != null) {
        println(error)
    } else {
        println(success.toString())
    }
}
```

{% /tab %}

{% tab label="Flutter" %}

```dart title=MyApp.dart
var demographic = {
  "age" : 32, // int
  "gender" : "Female", // string, "Male", "Female", "Gender Diverse"
  "country" : "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  "birthCountry" : "UK" // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
};

SahhaFlutter.postDemographic(demographic)
  .then((success) => {
    debugPrint(success.toString())
  })
  .catchError((error, stackTrace) => {
    debugPrint(error.toString())
  });
```

{% /tab %}

{% tab label="React Native" %}

```typescript title=MyApp.tsx
const demographic = {
  age: 32, // number
  gender: "Female", // string, "Male", "Female", "Gender Diverse",
  country: "NZ", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  birthCountry: "UK", // ISO 2 digit code, i.e. "US", "UK", "AU", etc.
  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}`);
  }
});
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript title=MyApp.js
Sahha.postDemographic({
	demographic: {
		gender: 'Female',
		age: 25
	}
}).then(
	function (response) {
		console.log(response.success);
	},
	function (error) {
		console.log(error);
	}
);
```

{% /tab %}

{% /tabs %}

---

## GET

An example `GET` of demographic info via the SDK.

{% tabs %}

{% tab label="iOS" %}

```swift title=MyApp.swift
Sahha.getDemographic() { error, demographic in
    if let error = error {
        print(error)
    }
    if let demographic = demographic {
        print(demographic)
    }
}
```

{% /tab %}

{% tab label="Android" %}

```kotlin title=MainActivity.kt
Sahha.getDemographic() { error, demographic ->
    if (error != null) {
        println(error)
    } else if (demographic != null) {
        println(demographic)
    }
}
```

{% /tab %}

{% tab label="Flutter" %}

```dart title=MyApp.dart
SahhaFlutter.getDemographic()
  .then((value) => {
    debugPrint(value)
  })
  .catchError((error, stackTrace) => {
    debugPrint(error.toString())
  });
```

{% /tab %}

{% tab label="React Native" %}

```typescript title=MyApp.tsx
Sahha.getDemographic((error: string, value: string) => {
  if error {
    console.error(`Error: $ {error}`);
  } else if value {
    console.log(`Value: $ {value}`);
  }
});
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript title=MyApp.js
Sahha.getDemographic().then(
	function (response) {
		console.log(response.demographic);
		const json = JSON.parse(response.demographic);
	},
	function (error) {
		console.log(error);
	}
);
```

{% /tab %}

{% /tabs %}
