npm package: @quantum-sa/cdp
Description: CDP is a customer data platform, where any company wishing to understand thier user behaviours can set it up and increase conversions. Talk to us to learn more at support[at]quantums.sa
Author: Quantum Dev
Latest version: 1.0.4

# @quantum-sa/cdp

###### What is a CDP?
CDP stands for Customer Data Platform. It's like a central hub where businesses store all the information they have about their customers. This includes things like their purchases, interactions, and preferences. The cool thing about CDPs is that they organize this data so businesses can use it to improve their marketing, customer service, and overall experience for customers. Think of it as a smart filing system for customer information

###### How to get it?
- Share your use-case with us [here](https://calendly.com/quantum-consultation/qmp?month=2024-02)
- We will understand your requirements and suggest you the best course of action
- We will share required environment variables which you can replace and after installing the SDK and start improving your conversions from day one!

## Installation
```npm install @quantum-sa/cdp```

## How-To
After you have installed the sdk, you will need to activate it by supplying some environment variables to be able to interact with it. Our support team will be responsible for sharing this information with you + onboarding you to get the most benefit out of it. 

Initial setup: [index.js]
```
import {SDK} from '@quantum-sa/cdp';
OR const {SDK} = require("@quantum-sa/cdp");

const client = new SDK({
    base_url: <BASE_URL>,
    site_id: <SITE_ID>,
    api_key: <API_KEY>
});
```

After this initial configuration, you will be able to interact with different modules inside this SDK as shown below:

#### Create Customer
```sh
  try {
    const customer = await client.customers.createCustomer
    ({
        ...customer_fields
    });
  } catch (error) {
    console.log(error.message);
  }
```

| Customer Fields | Type | Required
| ------ | ------ | ------ |
| local_id | string | true |
| email | string | true |
| name | string | true |
| interest | string | false |
| age | string | false |
| phone | string | false |
| company_name | string | false |
| job_position | string | false |
| profile_photo | string | false |
| custom_key | string | false |

#### Update Customer
```sh
  try {
    const customer = await client.customers.updateCustomer
    ({
        ...customer_fields
    });
    console.log(customer)
  } catch (error) {
    console.log(error.message);
  }
```
*updating a customer will replace the existing record, so make sure to send existing+updated payload alongside all the required fields.*

#### Create Event
After you are done with creating a customer, you can use their email to register events to create a journey of that user on your platform. Details are mentioned below: 

```sh
  try {
    const event = await client.events.createEvent
    ({
        ...event_fields
    });
    console.log(event)
  } catch (error) {
    console.log(error.message);
  }`
```

| Event Fields | Type | Required
| ------ | ------ | ------ |
| email | string | true |
| name | string | true |
| type | string | true ['event','page'] |
| data | object | false |

*you can only pass event|page as event type, and add additional data by passing it into the data object.*

#### Create Device
After you are done with creating a customer, you can use their email to associate devices. E.g. if you are running a mobile application, whenever changes their device upon login, you can send that information to this endpoint which will keep track of all device changes against a customer's email. This can become a unique data point to be used in marketing campaigns later on. 

```sh
  try {
    const device = await client.devices.createDevice
    ({
        ...device_fields
    });
    console.log(device)
  } catch (error) {
    console.log(error.message);
  }`
```

| Device Fields | Type | Required | Comments
| ------ | ------ | ------ | ------ |
| email | string | true | - |
| device_token | string | true | Unique token of the device |
| platform | string | true | e.g. Android/IPhone |
| attributes | object | false | See below |

You can use the following keys for device attributes:

| Attr. Fields | Type | Required | Comments
| ------ | ------ | ------ | ------ |
| device_os | string | false | e.g Android:13.0.1 |
| device_model | string | false | e.g. TFY-LX2 |
| app_version | string | false | e.g. current version of your app |
| pio_sdk_version | string | false | e.g. current version of this sdk |
| push_enabled | boolean | false | This is the user's preference of receiving PNs |
| push_token | string | false | We use FCM for push notification campaigns, so this should be a valid token received from FCM if it is configured |

## License
MIT