Skip to content

Commit

Permalink
Merge pull request #2 from ScreebApp/feat-tag-hooks
Browse files Browse the repository at this point in the history
feat(*): added callbacks to init and start commands
  • Loading branch information
MD4 authored Oct 11, 2023
2 parents cb5ffd8 + 41e9dfa commit de76166
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 158 deletions.
8 changes: 8 additions & 0 deletions packages/screeb-sdk-angular-example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ bootstrapApplication(AppComponent, {
importProvidersFrom(
ScreebModule.forRoot({
autoInit: true,
hooks: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onReady: (payload) => {
// eslint-disable-next-line no-console
console.log("onReady", payload);
},
version: "1.0.0",
},
userId: "[email protected]",
userProperties: {
authenticated: true,
Expand Down
22 changes: 16 additions & 6 deletions packages/screeb-sdk-angular/docs/classes/Screeb.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ Retrieves the current user identity.
```ts
console.log(await this.screeb.identityGet());
// {
// channel_id: "<UUID>",
// anonymous_id: "<UUID>",
// user_id: "<UUID>",
// is_ready: true,
// session_id: "<UUID>",
// session_start: "2023-05-04T16:30:15.882Z",
// session_end: "2023-05-04T17:02:09.087Z",
// channel_id: "<UUID>",
// is_ready: true,
// }
```

Expand Down Expand Up @@ -353,7 +353,7 @@ ___

### init

**init**(`websiteId`, `userId?`, `userProperties?`): `Promise`<`unknown`\>
**init**(`websiteId`, `userId?`, `userProperties?`, `hooks?`): `Promise`<`unknown`\>

Initializes Screeb tag.

Expand All @@ -369,7 +369,11 @@ this.screeb.init(
plan: '<user-plan>',
last_seen_at: new Date(),
authenticated: true
}
},
{
version: "1.0.0",
onReady: (payload) => console.log("Screeb SDK is ready!", payload),
},
);
```

Expand All @@ -380,6 +384,7 @@ this.screeb.init(
| `websiteId` | `string` | Your website/channel id. |
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | `PropertyRecord` | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date ``` |
| `hooks?` | `Hooks` | - |

#### Returns

Expand Down Expand Up @@ -425,7 +430,7 @@ ___

### surveyStart

**surveyStart**(`surveyId`, `allowMultipleResponses`, `hiddenFields`): `Promise`<`unknown`\>
**surveyStart**(`surveyId`, `allowMultipleResponses`, `hiddenFields`, `hooks?`): `Promise`<`unknown`\>

Starts a survey by its ID.

Expand All @@ -438,7 +443,11 @@ this.screeb.surveyStart(
{
color: "green",
article_id: 42
}
},
{
version: "1.0.0",
onSurveyShowed: (payload) => console.log("Survey showed", payload),
},
);
```

Expand All @@ -449,6 +458,7 @@ this.screeb.surveyStart(
| `surveyId` | `string` |
| `allowMultipleResponses` | `boolean` |
| `hiddenFields` | `PropertyRecord` |
| `hooks?` | `Hooks` |

#### Returns

Expand Down
9 changes: 9 additions & 0 deletions packages/screeb-sdk-angular/docs/classes/ScreebConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Configuration of Screeb module
### Properties

- [autoInit](ScreebConfig.md#autoinit)
- [hooks](ScreebConfig.md#hooks)
- [options](ScreebConfig.md#options)
- [shouldLoad](ScreebConfig.md#shouldload)
- [userId](ScreebConfig.md#userid)
Expand All @@ -39,6 +40,14 @@ if `true`, 'init' does not need to be called manually

___

### hooks

`Optional` **hooks**: `Hooks`

Hooks to define callback for various event

___

### options

`Optional` **options**: `ScreebOptions`
Expand Down
6 changes: 5 additions & 1 deletion packages/screeb-sdk-angular/docs/classes/ScreebModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ ScreebModule.forRoot({
plan: '<user-plan>',
last_seen_at: new Date(),
authenticated: true
}
},
{
version: "1.0.0",
onReady: (payload) => console.log("Screeb SDK is ready!", payload),
},
})
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@angular/core";
import { PropertyRecord, ScreebOptions } from "@screeb/sdk-browser";
import { Hooks, PropertyRecord, ScreebOptions } from "@screeb/sdk-browser";

/** Configuration of Screeb module */
@Injectable({ providedIn: "root" })
Expand All @@ -10,6 +10,8 @@ export class ScreebConfig {
userId?: string;
/** The properties of your user. */
userProperties?: PropertyRecord;
/** Hooks to define callback for various event */
hooks?: Hooks;
/**
* Indicates if Screeb should be automatically loaded.
* This will ping to the Screeb servers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export class ScreebModule {
* plan: '<user-plan>',
* last_seen_at: new Date(),
* authenticated: true
* }
* },
* {
* version: "1.0.0",
* onReady: (payload) => console.log("Screeb SDK is ready!", payload),
* },
* })
* ```
*/
Expand All @@ -42,7 +46,12 @@ export class ScreebModule {
}

if ((config.autoInit ?? false) && config.websiteId) {
screeb.init(config.websiteId, config.userId, config.userProperties);
screeb.init(
config.websiteId,
config.userId,
config.userProperties,
config.hooks
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ export class Screeb {
* ```ts
* console.log(await this.screeb.identityGet());
* // {
* // channel_id: "<UUID>",
* // anonymous_id: "<UUID>",
* // user_id: "<UUID>",
* // is_ready: true,
* // session_id: "<UUID>",
* // session_start: "2023-05-04T16:30:15.882Z",
* // session_end: "2023-05-04T17:02:09.087Z",
* // channel_id: "<UUID>",
* // is_ready: true,
* // }
* ```
*/
Expand Down Expand Up @@ -309,18 +309,28 @@ export class Screeb {
* {
* color: "green",
* article_id: 42
* }
* },
* {
* version: "1.0.0",
* onSurveyShowed: (payload) => console.log("Survey showed", payload),
* },
* );
* ```
*/
public async surveyStart(
surveyId: string,
allowMultipleResponses: boolean,
hiddenFields: _Screeb.PropertyRecord
hiddenFields: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks
) {
await this.ensureScreeb("surveyStart");

return _Screeb.surveyStart(surveyId, allowMultipleResponses, hiddenFields);
return _Screeb.surveyStart(
surveyId,
allowMultipleResponses,
hiddenFields,
hooks
);
}

/**
Expand Down Expand Up @@ -388,20 +398,25 @@ export class Screeb {
* plan: '<user-plan>',
* last_seen_at: new Date(),
* authenticated: true
* }
* },
* {
* version: "1.0.0",
* onReady: (payload) => console.log("Screeb SDK is ready!", payload),
* },
* );
* ```
*/
public async init(
websiteId: string,
userId?: string,
userProperties?: _Screeb.PropertyRecord
userProperties?: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks
) {
await this.ensureScreeb("init", true);

this.isInitialized = true;

return await _Screeb.init(websiteId, userId, userProperties);
return await _Screeb.init(websiteId, userId, userProperties, hooks);
}

/**
Expand Down
Loading

0 comments on commit de76166

Please sign in to comment.