Skip to content

Commit

Permalink
feat(*): force language
Browse files Browse the repository at this point in the history
  • Loading branch information
cley44 committed Sep 30, 2024
1 parent dbe90a2 commit 48468e5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 17 deletions.
8 changes: 6 additions & 2 deletions packages/screeb-sdk-angular/docs/classes/Screeb.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ ___

### init

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

Initializes Screeb tag.

Expand All @@ -365,6 +365,7 @@ Initializes Screeb tag.
| `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` | - |
| `language?` | `string` | Force a specific language for the tag. eg: 'en' |

#### Returns

Expand All @@ -387,6 +388,7 @@ this.screeb.init(
version: "1.0.0",
onReady: (payload) => console.log("Screeb SDK is ready!", payload),
},
"en"
);
```

Expand Down Expand Up @@ -436,7 +438,7 @@ ___

### surveyStart

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

Starts a survey by its ID.

Expand All @@ -448,6 +450,7 @@ Starts a survey by its ID.
| `allowMultipleResponses` | `boolean` |
| `hiddenFields` | `PropertyRecord` |
| `hooks?` | `Hooks` |
| `language?` | `string` |

#### Returns

Expand All @@ -467,6 +470,7 @@ this.screeb.surveyStart(
version: "1.0.0",
onSurveyShowed: (payload) => console.log("Survey showed", payload),
},
"en"
);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,25 @@ export class Screeb {
* version: "1.0.0",
* onSurveyShowed: (payload) => console.log("Survey showed", payload),
* },
* "en"
* );
* ```
*/
public async surveyStart(
surveyId: string,
allowMultipleResponses: boolean,
hiddenFields: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks
hooks?: _Screeb.Hooks,
language?: string
) {
await this.ensureScreeb("surveyStart");

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

Expand Down Expand Up @@ -387,6 +390,7 @@ export class Screeb {
* - No more than 1000 attributes
* - Supported types for values: string, number, boolean and Date
* ```
* @param language Force a specific language for the tag. eg: 'en'
*
* @example
* ```ts
Expand All @@ -404,20 +408,28 @@ export class Screeb {
* version: "1.0.0",
* onReady: (payload) => console.log("Screeb SDK is ready!", payload),
* },
* "en"
* );
* ```
*/
public async init(
websiteId: string,
userId?: string,
userProperties?: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks
hooks?: _Screeb.Hooks,
language?: string
) {
await this.ensureScreeb("init", true);

this.isInitialized = true;

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

/**
Expand Down
8 changes: 6 additions & 2 deletions packages/screeb-sdk-browser/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ ___

### init

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

Initializes Screeb tag.

Expand All @@ -714,6 +714,7 @@ Initializes Screeb tag.
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | [`PropertyRecord`](README.md#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`](README.md#hooks) | Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden or when a question is replied. |
| `language?` | `string` | Force a specific language for the tag. eg: 'en' |

#### Returns

Expand All @@ -738,6 +739,7 @@ Screeb.init(
version: "1.0.0",
onReady: (payload) => console.log("Screeb SDK is ready!", payload),
},
"en"
);
```

Expand Down Expand Up @@ -813,7 +815,7 @@ ___

### surveyStart

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

Starts a survey by its ID.

Expand All @@ -825,6 +827,7 @@ Starts a survey by its ID.
| `allowMultipleResponses` | `boolean` | `true` |
| `hiddenFields` | [`PropertyRecord`](README.md#propertyrecord) | `{}` |
| `hooks?` | [`Hooks`](README.md#hooks) | `undefined` |
| `language?` | `string` | `undefined` |

#### Returns

Expand All @@ -846,6 +849,7 @@ Screeb.surveyStart(
version: "1.0.0",
onSurveyShowed: (payload) => console.log("Survey showed", payload),
},
"en"
);
```

Expand Down
19 changes: 18 additions & 1 deletion packages/screeb-sdk-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export const load = (options: ScreebOptions = {}) =>
* @param hooks Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden
* or when a question is replied.
*
* @param language Force a specific language for the tag. eg: 'en'
*
* @example
* ```ts
* import * as Screeb from "@screeb/sdk-browser";
Expand All @@ -118,6 +120,7 @@ export const load = (options: ScreebOptions = {}) =>
* version: "1.0.0",
* onReady: (payload) => console.log("Screeb SDK is ready!", payload),
* },
* "en"
* );
* ```
*/
Expand All @@ -126,8 +129,15 @@ export const init = (
userId?: string,
userProperties?: PropertyRecord,
hooks?: Hooks,
language?: string,
) => {
let identityObject;
let identityObject:
| {
hooks?: Hooks;
identity?: { id?: string; properties?: PropertyRecord };
language?: string;
}
| undefined;

if (userId || userProperties) {
identityObject = {
Expand All @@ -139,6 +149,10 @@ export const init = (
};
}

if (language) {
identityObject = { ...identityObject, language };
}

return callScreebCommand("init", websiteId, identityObject);
};

Expand Down Expand Up @@ -426,6 +440,7 @@ export const surveyClose = () => callScreebCommand("survey.close");
* version: "1.0.0",
* onSurveyShowed: (payload) => console.log("Survey showed", payload),
* },
* "en"
* );
* ```
*/
Expand All @@ -434,9 +449,11 @@ export const surveyStart = (
allowMultipleResponses = true,
hiddenFields: PropertyRecord = {},
hooks?: Hooks,
language?: string,
) =>
callScreebCommand("survey.start", surveyId, {
allow_multiple_responses: allowMultipleResponses,
language: language,
hidden_fields: hiddenFields,
hooks: hooks,
});
Expand Down
16 changes: 11 additions & 5 deletions packages/screeb-sdk-react/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ ___

### InitFunction

Ƭ **InitFunction**: (`websiteId`: `string`, `userId?`: `string`, `userProperties?`: `PropertyRecord`) => `Promise`<`void`\>
Ƭ **InitFunction**: (`websiteId`: `string`, `userId?`: `string`, `userProperties?`: `PropertyRecord`, `hooks?`: `Hooks`, `language?`: `string`) => `Promise`<`void`\>

#### Type declaration

▸ (`websiteId`, `userId?`, `userProperties?`): `Promise`<`void`\>
▸ (`websiteId`, `userId?`, `userProperties?`, `hooks?`, `language?`): `Promise`<`void`\>

Initializes Screeb tag.

Expand All @@ -379,6 +379,8 @@ Initializes Screeb tag.
| `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` | - |
| `language?` | `string` | Force a specific language for the tag. eg: 'en' |

##### Returns

Expand All @@ -398,7 +400,8 @@ init(
plan: '<user-plan>',
last_seen_at: new Date(),
authenticated: true
}
},
"en"
);
```

Expand Down Expand Up @@ -473,6 +476,7 @@ Properties of Screeb provider
| Name | Type | Description |
| :------ | :------ | :------ |
| `hooks?` | `Hooks` | Hooks to define callback for various event |
| `language?` | `string` | The language you want to force |
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | `PropertyRecord` | The properties of your user. |
| `websiteId` | `string` | Your website/channel id. |
Expand Down Expand Up @@ -513,11 +517,11 @@ ___

### SurveyStartFunction

Ƭ **SurveyStartFunction**: (`surveyId`: `string`, `allowMultipleResponses`: `boolean`, `hiddenFields`: `PropertyRecord`) => `Promise`<`unknown`\>
Ƭ **SurveyStartFunction**: (`surveyId`: `string`, `allowMultipleResponses`: `boolean`, `hiddenFields`: `PropertyRecord`, `hooks`: `Hooks`, `language`: `string`) => `Promise`<`unknown`\>

#### Type declaration

▸ (`surveyId`, `allowMultipleResponses`, `hiddenFields`): `Promise`<`unknown`\>
▸ (`surveyId`, `allowMultipleResponses`, `hiddenFields`, `hooks`, `language`): `Promise`<`unknown`\>

Starts a survey by its ID.

Expand All @@ -528,6 +532,8 @@ Starts a survey by its ID.
| `surveyId` | `string` |
| `allowMultipleResponses` | `boolean` |
| `hiddenFields` | `PropertyRecord` |
| `hooks` | `Hooks` |
| `language` | `string` |

##### Returns

Expand Down
8 changes: 6 additions & 2 deletions packages/screeb-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const ScreebProvider: React.FC<
userId,
userProperties,
hooks,
language,
children,
shouldLoad = !isSSR,
autoInit = false,
Expand Down Expand Up @@ -145,12 +146,13 @@ export const ScreebProvider: React.FC<
userId?: string,
userProperties?: Screeb.PropertyRecord,
hooks?: Screeb.Hooks,
language?: string,
) => {
await ensureScreeb(
"init",
() => {
if (!isInitialized) {
Screeb.init(websiteId, userId, userProperties, hooks);
Screeb.init(websiteId, userId, userProperties, hooks, language);

isInitialized = true;
}
Expand All @@ -174,7 +176,7 @@ export const ScreebProvider: React.FC<

if (autoInit) {
if (websiteId) {
await init(websiteId, userId, userProperties, hooks);
await init(websiteId, userId, userProperties, hooks, language);
} else {
logger.log(
"warn",
Expand All @@ -198,13 +200,15 @@ export const ScreebProvider: React.FC<
allowMultipleResponses: boolean,
hiddenFields: Screeb.PropertyRecord,
hooks?: Screeb.Hooks,
language?: string,
) =>
await ensureScreeb("surveyStart", () =>
Screeb.surveyStart(
surveyId,
allowMultipleResponses,
hiddenFields,
hooks,
language,
),
),
[],
Expand Down
10 changes: 9 additions & 1 deletion packages/screeb-sdk-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type ScreebProps = {
userProperties?: PropertyRecord;
/** Hooks to define callback for various event */
hooks?: Hooks;
/** The language you want to force */
language?: string;
};

/**
Expand Down Expand Up @@ -266,6 +268,7 @@ export type IdentityResetFunction = () => Promise<unknown>;
* - No more than 1000 attributes
* - Supported types for values: string, number, boolean and Date
* ```
* @param language Force a specific language for the tag. eg: 'en'
*
* @example
* ```ts
Expand All @@ -280,14 +283,17 @@ export type IdentityResetFunction = () => Promise<unknown>;
* plan: '<user-plan>',
* last_seen_at: new Date(),
* authenticated: true
* }
* },
* "en"
* );
* ```
*/
export type InitFunction = (
websiteId: string,
userId?: string,
userProperties?: PropertyRecord,
hooks?: Hooks,
language?: string,
) => Promise<void>;

/**
Expand Down Expand Up @@ -339,6 +345,8 @@ export type SurveyStartFunction = (
surveyId: string,
allowMultipleResponses: boolean,
hiddenFields: PropertyRecord,
hooks: Hooks,
language: string,
) => Promise<unknown>;

/**
Expand Down

0 comments on commit 48468e5

Please sign in to comment.