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 24, 2024
1 parent dbe90a2 commit cc646ae
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
6 changes: 4 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?`, `forceLang?`): `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` | - |
| `forceLang?` | `string` | - |

#### Returns

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

### surveyStart

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

Starts a survey by its ID.

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

#### Returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,17 @@ export class Screeb {
surveyId: string,
allowMultipleResponses: boolean,
hiddenFields: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks
hooks?: _Screeb.Hooks,
forceLang?: string
) {
await this.ensureScreeb("surveyStart");

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

Expand Down Expand Up @@ -411,13 +413,20 @@ export class Screeb {
websiteId: string,
userId?: string,
userProperties?: _Screeb.PropertyRecord,
hooks?: _Screeb.Hooks
hooks?: _Screeb.Hooks,
forceLang?: 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,
forceLang
);
}

/**
Expand Down
6 changes: 4 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?`, `forceLang?`): `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. |
| `forceLang?` | `string` | - |

#### Returns

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

### surveyStart

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

Starts a survey by its ID.

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

#### Returns

Expand Down
15 changes: 14 additions & 1 deletion packages/screeb-sdk-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,15 @@ export const init = (
userId?: string,
userProperties?: PropertyRecord,
hooks?: Hooks,
forceLang?: string,
) => {
let identityObject;
let identityObject:
| {
hooks?: Hooks;
identity?: { id?: string; properties?: PropertyRecord };
forceLang?: string;
}
| undefined;

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

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

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

Expand Down Expand Up @@ -434,9 +445,11 @@ export const surveyStart = (
allowMultipleResponses = true,
hiddenFields: PropertyRecord = {},
hooks?: Hooks,
forceLang?: string,
) =>
callScreebCommand("survey.start", surveyId, {
allow_multiple_responses: allowMultipleResponses,
forceLang: forceLang,
hidden_fields: hiddenFields,
hooks: hooks,
});
Expand Down
13 changes: 9 additions & 4 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`, `forceLang?`: `string`) => `Promise`<`void`\>

#### Type declaration

▸ (`websiteId`, `userId?`, `userProperties?`): `Promise`<`void`\>
▸ (`websiteId`, `userId?`, `userProperties?`, `hooks?`, `forceLang?`): `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` | - |
| `forceLang?` | `string` | Force the language of the tag. |

##### Returns

Expand Down Expand Up @@ -472,6 +474,7 @@ Properties of Screeb provider

| Name | Type | Description |
| :------ | :------ | :------ |
| `forceLang?` | `string` | The language you want to force |
| `hooks?` | `Hooks` | Hooks to define callback for various event |
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | `PropertyRecord` | The properties of your user. |
Expand Down Expand Up @@ -513,11 +516,11 @@ ___

### SurveyStartFunction

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

#### Type declaration

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

Starts a survey by its ID.

Expand All @@ -528,6 +531,8 @@ Starts a survey by its ID.
| `surveyId` | `string` |
| `allowMultipleResponses` | `boolean` |
| `hiddenFields` | `PropertyRecord` |
| `hooks` | `Hooks` |
| `forceLang` | `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,
forceLang,
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,
forceLang?: string,
) => {
await ensureScreeb(
"init",
() => {
if (!isInitialized) {
Screeb.init(websiteId, userId, userProperties, hooks);
Screeb.init(websiteId, userId, userProperties, hooks, forceLang);

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, forceLang);
} else {
logger.log(
"warn",
Expand All @@ -198,13 +200,15 @@ export const ScreebProvider: React.FC<
allowMultipleResponses: boolean,
hiddenFields: Screeb.PropertyRecord,
hooks?: Screeb.Hooks,
forceLang?: string,
) =>
await ensureScreeb("surveyStart", () =>
Screeb.surveyStart(
surveyId,
allowMultipleResponses,
hiddenFields,
hooks,
forceLang,
),
),
[],
Expand Down
7 changes: 7 additions & 0 deletions 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 */
forceLang?: 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 forceLang Force the language of the tag.
*
* @example
* ```ts
Expand All @@ -288,6 +291,8 @@ export type InitFunction = (
websiteId: string,
userId?: string,
userProperties?: PropertyRecord,
hooks?: Hooks,
forceLang?: string,
) => Promise<void>;

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

/**
Expand Down

0 comments on commit cc646ae

Please sign in to comment.