|
1 | | -# `@userlist/web` |
| 1 | +# @userlist/web |
2 | 2 |
|
3 | | -> TODO: description |
| 3 | +This package helps with client side tracking for [Userlist](http://userlist.com). |
| 4 | + |
| 5 | +> For server side tracking on Node.js, please use [@userlist/push](https://github.com/userlist/userlist-javascript/tree/main/packages/push). |
| 6 | +
|
| 7 | +## Installation |
| 8 | + |
| 9 | +To install this package, use one of the commands corresponding to your package manager. |
| 10 | + |
| 11 | +Via NPM: |
| 12 | + |
| 13 | +```shell |
| 14 | +npm install @userlist/web |
| 15 | +``` |
| 16 | + |
| 17 | +Via Yarn: |
| 18 | + |
| 19 | +```shell |
| 20 | +yarn add @userlist/web |
| 21 | +``` |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +To initialize the Userlist client, you have to pass it a user token that you generate on your backend. For details on how to create a user token, please refer to the [documentation](https://userlist.com/docs/developers/in-app-messages/#generating-user-tokens). |
| 26 | + |
| 27 | +```javascript |
| 28 | +import Userlist from "@userlist/web"; |
| 29 | + |
| 30 | +// With a static token |
| 31 | +const userlist = new Userlist("userlist-user-token"); |
| 32 | + |
| 33 | +// With a promise that retuns a token |
| 34 | +const token = fetch("http://example.com/token") |
| 35 | + .then((response) => response.json()) |
| 36 | + .then((data) => data.userlistToken); |
| 37 | + |
| 38 | +const userlist = new Userlist(token); |
| 39 | +``` |
4 | 40 |
|
5 | 41 | ## Usage |
6 | 42 |
|
| 43 | +You can only update data of the user that the user token was generated for. To update other data, please use server side tracking. |
| 44 | + |
| 45 | +### Tracking User Properties |
| 46 | + |
| 47 | +To send user data into Userlist, use the `userlist.identify` method. This method will create a new user if the user doesn't exist yet, or update the existing user if it does. Properties that aren't present in the payload are ignored and remain unchanged. |
| 48 | + |
| 49 | +```javascript |
| 50 | +userlist.identify({ |
| 51 | + email: user.email, |
| 52 | + properties: { |
| 53 | + first_name: user.first_name, |
| 54 | + last_name: user.last_name, |
| 55 | + }, |
| 56 | +}); |
7 | 57 | ``` |
8 | | -const web = require('@userlist/web'); |
9 | 58 |
|
10 | | -// TODO: DEMONSTRATE API |
| 59 | +### Tracking User Events |
| 60 | + |
| 61 | +To track custom events use the `userlist.track` method. This method will create a new user if the user doesn't exist yet, or update the existing user if it does. |
| 62 | + |
| 63 | +```javascript |
| 64 | +userlist.track({ |
| 65 | + name: "project_created", |
| 66 | + properties: { |
| 67 | + project_name: project.name, |
| 68 | + }, |
| 69 | +}); |
11 | 70 | ``` |
| 71 | + |
| 72 | +### Resetting |
| 73 | + |
| 74 | +If you want to reset the connection to our services to be able to start tracking a new user, please call `destroy` before creating a new Userlist client. |
| 75 | + |
| 76 | +```javascript |
| 77 | +userlist.destroy(); |
| 78 | +``` |
| 79 | + |
| 80 | +## Contributing |
| 81 | + |
| 82 | +Bug reports and pull requests are welcome on GitHub at https://github.com/userlist/userlist-javascript. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. |
| 83 | + |
| 84 | +## License |
| 85 | + |
| 86 | +The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
| 87 | + |
| 88 | +## Code of Conduct |
| 89 | + |
| 90 | +Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-javascript/blob/main/CODE_OF_CONDUCT.md). |
| 91 | + |
| 92 | +## What is Userlist? |
| 93 | + |
| 94 | +[](https://userlist.com/) |
| 95 | + |
| 96 | +[Userlist](https://userlist.com/) allows you to onboard and engage your SaaS users with targeted behavior-based campaigns using email or in-app messages. |
| 97 | + |
| 98 | +Userlist was started in 2017 as an alternative to bulky enterprise messaging tools. We believe that running SaaS products should be more enjoyable. Learn more [about us](https://userlist.com/about-us/). |
0 commit comments