Skip to content

Commit 6d7515f

Browse files
authored
Merge pull request #12 from journy-io/id-mods
added identification object to upsertUser, upsertAccount, link, addEv…
2 parents 966c0bc + 9c78be9 commit 6d7515f

10 files changed

+247
-186
lines changed

.github/workflows/build-and-release.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ jobs:
1313
node-version: "12.x"
1414
registry-url: "https://registry.npmjs.org"
1515
scope: "@journyio"
16-
- name: Cache node modules
17-
uses: actions/cache@v2
18-
env:
19-
cache-name: cache-node-modules
20-
with:
21-
# npm cache files are stored in `~/.npm` on Linux/macOS
22-
path: ~/.npm
23-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
24-
restore-keys: |
25-
${{ runner.os }}-build-${{ env.cache-name }}-
26-
${{ runner.os }}-build-
27-
${{ runner.os }}-
2816
- run: npm install
2917
- run: npm run lint
3018
- run: npm run test

.github/workflows/lint-and-test.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ jobs:
99
node-version: [12.x, 13.x, 14.x]
1010
steps:
1111
- uses: actions/checkout@v2
12-
- name: Cache node modules
13-
uses: actions/cache@v2
14-
env:
15-
cache-name: cache-node-modules
16-
with:
17-
# npm cache files are stored in `~/.npm` on Linux/macOS
18-
path: ~/.npm
19-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
20-
restore-keys: |
21-
${{ runner.os }}-build-${{ env.cache-name }}-
22-
${{ runner.os }}-build-
23-
${{ runner.os }}-
2412
- name: Use Node.js ${{ matrix.node-version }}
2513
uses: actions/setup-node@v1
2614
with:

README.md

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ _Note: when sending an empty value (`""`) as value for a property, the property
6767

6868
```ts
6969
await client.upsertUser({
70-
// required
70+
// Must provide either an email or userId or both
7171
userId: "userId", // Unique identifier for the user in your database
72-
email: "name@domain.tld",
72+
email: "john@doe.tld",
7373

7474
// optional
7575
properties: {
76+
full_name: "John Doe",
77+
first_name: "John",
78+
last_name: "Doe",
7679
age: 26,
77-
name: "John Doe",
7880
is_developer: true,
7981
registered_at: new Date(/* ... */),
8082
this_property_will_be_deleted: "",
@@ -88,33 +90,39 @@ _Note: when sending an empty value (`""`) as value for a property, the property
8890

8991
```ts
9092
await client.upsertAccount({
91-
// required
93+
// Must provide either an domain or accountId or both
9294
accountId: "accountId", // Unique identifier for the account in your database
93-
name: "journy.io",
95+
domain: "acme-inc.com",
9496

9597
// optional
9698
properties: {
97-
age: 26,
98-
name: "John Doe",
99-
is_developer: true,
99+
name: "ACME, Inc",
100+
total_amount_of_users: 53,
101+
is_paying_account: true,
100102
registered_at: new Date(/* ... */),
101103
this_property_will_be_deleted: "",
102104
},
103105

104106
// optional
105-
members: ["userId", "userId"], // Unique identifier for the user in your database
107+
members: [
108+
{ userId: "userId" }, // userID: Unique identifier for the user in your database
109+
{ userId: "userId" }
110+
]
106111
});
107112
```
108113

109-
#### Link web visitor to an app user
114+
#### Link web activity to a user
110115

111-
You can link a web visitor to a user in your application when you have our snippet installed on your website. The snippet sets a cookie named `__journey`. If the cookie exists, you can link the web visitor to the user that is currently logged in:
116+
You can link web activity to a user in your application when you have our snippet installed on your website. The snippet sets a cookie named `__journey`. If the cookie exists, you can link the web activity to the user that is currently logged in:
112117

113118
```ts
114119
if (request.cookies["__journey"]) {
115120
const result = await client.link({
116121
deviceId: request.cookies["__journey"],
122+
117123
userId: request.user.id, // Unique identifier for the user in your database
124+
// or
125+
email: request.user.email,
118126
});
119127
}
120128
```
@@ -124,16 +132,29 @@ if (request.cookies["__journey"]) {
124132
#### Add event
125133

126134
```ts
135+
import { AccountIdentified } from "./AccountIdentified";
127136
import { Event } from "./Client";
128-
129-
event = Event.forUser("login", "userId");
130-
event = Event.forUser("some_historic_event", "userId").happenedAt(new Date(...));
131-
event = Event.forAccount("reached_monthly_volume", "accountId").withMetadata({
132-
"number": 1313,
133-
"string": "string",
134-
"boolean": true,
135-
});
136-
event = Event.forUserInAccount("updated_settings", "userId", "accountId");
137+
import { UserIdentified } from "./UserIdentified";
138+
139+
event = Event.forUser("login", UserIdentified.byUserId("userId"));
140+
141+
event = Event.forUser("some_historic_event", UserIdentified.byUserId("userId"))
142+
.happenedAt(new Date(...))
143+
;
144+
145+
event = Event.forAccount("reached_monthly_volume", AccountIdentified.byAccountId("accountId"))
146+
.withMetadata({
147+
"number": 1313,
148+
"string": "string",
149+
"boolean": true,
150+
})
151+
;
152+
153+
event = Event.forUserInAccount(
154+
"updated_settings",
155+
UserIdentified.byUserId("userId"),
156+
AccountIdentified.byAccountId("accountId")
157+
);
137158

138159
await client.addEvent(event);
139160
```

lib/AccountIdentified.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export class AccountIdentified {
2+
constructor(
3+
private readonly accountId: string | undefined,
4+
private readonly domain: string | undefined
5+
) {
6+
if (!this.accountId && !this.domain) {
7+
throw new Error("Account ID or domain needs to set!");
8+
}
9+
}
10+
11+
getAccountId() {
12+
return this.accountId;
13+
}
14+
15+
getDomain() {
16+
return this.domain;
17+
}
18+
19+
static byAccountId(accountId: string) {
20+
return new AccountIdentified(accountId, undefined);
21+
}
22+
23+
static byDomain(domain: string) {
24+
return new AccountIdentified(undefined, domain);
25+
}
26+
}

0 commit comments

Comments
 (0)