# deepin-js-sdk

> Javascript SDK to use deepin platform

Latest version **1.2.0** (published 2023-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install deepin-js-sdk
pnpm add deepin-js-sdk
yarn add deepin-js-sdk
bun add deepin-js-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2023-05-29 |
| First published | 2022-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 102.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | fingerpich, mydeepinir |

## Links

- npm: https://www.npmjs.com/package/deepin-js-sdk
- Repository: https://github.com/mydeepinir/SDK
- Homepage: https://github.com/mydeepinir/SDK#readme
- Issues: https://github.com/mydeepinir/SDK/issues
- npm.io page: https://npm.io/package/deepin-js-sdk

## Dependencies (3)

- [unfetch](https://npm.io/package/unfetch.md) ^4.2.0
- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.1.5
- [@lukeed/uuid](https://npm.io/package/@lukeed/uuid.md) ^2.0.0

## Recent versions

- 1.2.0 (latest) — 2023-05-29
- 1.1.4 — 2023-03-06
- 1.1.3 — 2023-02-21
- 1.1.2 — 2023-02-05
- 1.1.1 — 2022-12-17
- 1.1.0 — 2022-11-27
- 1.0.0 — 2022-11-16

## README

# Deepin SDK

[![MIT License][license-image]][license-url]
[![NPM version][npm-version-image]][npm-url]
[![Package Quality][packagequality-image]][packagequality-url]
[![TypeScript][typescript-image]](https://typescriptlang.org)

## Table of Contents

- [How to install deepin sdk](#how-to-install-and-import-deepin-sdk)
  - [With package managers(npm, yarn)](#with-package-managers)
  - [Without package managers](#without-package-managers)
- [Initialization And Test](#initialization-and-test)
- [Api](#api)
  - [Init](#init)
  - [Identify](#identify)
  - [Page](#page)
  - [Track](#track)
  - [Group](#group)
  - [Alias](#alias)

# How to install and import deepin SDK

`deepin-sdk` can be used in react, vue, svelte, react-native, flutter, cordova and in other capacities you may require that can run javascript code as follows:

### With Package Managers

You can use one of the following commands to install the sdk.

```shell
  npm i deepin-js-sdk
  yarn add deepin-js-sdk
```

The following code shows you how could it be imported in es6 or 7 or typescript.

```js
  import deepIn from 'deepin-js-sdk'
  ...
```

[Code Example In Vue](https://github.com/mydeepinir/SDK/blob/main/demos/es-demo/src/App.vue)

### Without Package Managers

Copy the following line in an html file

```html
<script src="https://dash.mydeepin.ir/download/deepin-js-sdk-v1.1.3.js"></script>
<script>
  const deepIn = window.Deepin
  ...
</script>
```

[Code Example In VanillaJS](https://github.com/mydeepinir/SDK/blob/main/demos/umd-demo/index.html)

# Initialization And Test

First you need to create a new source(web sdk) in [deepin panel](https://dash.mydeepin.ir) and get a writekey then use `deepin` instance to be able to initialize it by the following code:

```js
deepIn.init(writeKey);
```

Now you are ready to send events using this instance,
It creates a bundle of events and send them together by default. Thus, for the first time you can use the following code to send a page event instantly and check whether the event has been sent successfully.

```js
deepIn.init(writekey);
deepIn.page(); // calls a page event
deepIn.flush(); // cleanse the queue and sends all the events
```

#### Initialize sdk in react-native

In `react-native` make sure you call init method after intrack initialization

```js
if (!(await InTrack.isInitialized())) {
  //init inTrack
  await InTrack.init({
    appKey: "INTRACK_APP_KEY__",
    iosAuthKey: "ّINTRACK_AUTH_KEY_FOR_IOS__",
    androidAuthKey: "INTRACK_AUTH_KEY_FOR_ANDROID__",
  });
  InTrack.start();
  // other inTrack related codes...

  // init DeepIn:
  DeepIn.init(writekey);
}
```

# Api

## Init

Use the init method to initialize the deepIn SDK.

```js
deepIn.init(writeKey);
```

#### writeKey

The given writekey for the source you have created in deepin panel.



## Identify

Use the identify method to link your users and their actions, to a recognizable userId and traits.

```js
deepIn.identify(userId, [traits], [commonProps]);
```

#### userId

The database ID for the user. If you don’t know who the user is yet, you can set the userId an empty string and just record traits.

#### traits (optional)

A dictionary of traits you know about the user, you can read more about traits in the [identify traits type](/src/types/identify.ts)

#### commonProps (optional)

A dictionary of properties, you can read more about common properties in the [common properties type](/src/types/common.ts)

```js
deepIn.identify("12091906-01011992", {
  firstName: "Grace Hopper",
  username: "grace@usnavy.gov",
});
```

## Track

The Track method lets you record actions your users perform.

```js
deepIn.track(event, [properties]);
```

#### event

The name of the event you’re tracking.

#### category

The category of the event you’re tracking.

#### commonProps (optional)

A dictionary of properties for the event, If the event was 'Added to Cart', it might have properties like price and productType, you can read more about common properties in the [common properties type](/src/types/common.ts)

```js
deepIn.track("Added to Cart", "Sell", {
  properties: {
    price: 1000,
    productType: "mobile",
  },
});
```

## Page

The Page method lets you record page views on your website, along with optional extra information about the page viewed by the user.

```js
deepIn.page([category], [channel], [properties]);
```

#### category (optional)

The category of the page. Useful for cases like ecommerce where many pages might live under a single category.

#### channel (optional)

The channel of the page.

#### commonProps (optional)

A dictionary of properties, you can read more about common properties in the [common properties type](/src/types/common.ts)

```js
deepIn.page("Pricing");
```

```js
deepIn.page("Pricing", "", {
  page: {
    title: "Deepin Pricing",
    url: "https://mydeepin.ir/pricing",
    referrer: "https://mydeepin.ir",
  },
});
```

## Group

The Group method associates an identified user with a company, organization, project, workspace, team, tribe, platoon, assemblage, cluster, troop, gang, party, society or any other collective noun you come up with for the same concept.

```js
deepIn.group(groupId, [traits], [commonProps]);
```

#### groupId

The Group ID to associate with the current user.

#### traits (optional)

A dictionary of traits for the group. Example traits for a group include address, website, and employees. you can read more about traits in the [group traits type](/src/types/group.ts)

#### commonProps (optional)

A dictionary of properties, you can read more about common properties in the [common properties type](/src/types/common.ts)

```js
deepIn.group("UNIVAC Working Group", {
  employees: "Eckert–Mauchly",
  industry: "IT",
});
```

## Alias

The Alias method combines two unassociated user identities. Segment usually handles aliasing automatically when you call identify on a user, however some tools require an explicit alias call.

```js
deepIn.alias(userId, [previousId]);
```

#### userId

The new user ID you want to associate with the user.

#### previousId (optional)

The previous ID that the user was recognized by. This defaults to the currently identified user’s ID.

[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE
[npm-url]: https://npmjs.com/package/deepin-js-sdk
[typescript-image]: http://badgen.net/badge/icon/typescript?icon=typescript&label
[npm-version-image]: http://img.shields.io/npm/v/deepin-js-sdk.svg?style=flat
[packagequality-image]: http://npm.packagequality.com/shield/deepin-js-sdk.svg
[packagequality-url]: http://packagequality.com/#?package=deepin-js-sdk

---
_Source: https://npm.io/package/deepin-js-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
