From 48468e5e19c32f7e2ab031b399c17cd488787385 Mon Sep 17 00:00:00 2001 From: clement Date: Tue, 24 Sep 2024 15:25:22 +0200 Subject: [PATCH] feat(*): force language --- .../screeb-sdk-angular/docs/classes/Screeb.md | 8 ++++++-- .../screeb-sdk-angular/src/lib/screeb.ts | 20 +++++++++++++++---- packages/screeb-sdk-browser/docs/README.md | 8 ++++++-- packages/screeb-sdk-browser/src/index.ts | 19 +++++++++++++++++- packages/screeb-sdk-react/docs/README.md | 16 ++++++++++----- packages/screeb-sdk-react/src/provider.tsx | 8 ++++++-- packages/screeb-sdk-react/src/types.ts | 10 +++++++++- 7 files changed, 72 insertions(+), 17 deletions(-) diff --git a/packages/screeb-sdk-angular/docs/classes/Screeb.md b/packages/screeb-sdk-angular/docs/classes/Screeb.md index ce95a22..f2e0a59 100644 --- a/packages/screeb-sdk-angular/docs/classes/Screeb.md +++ b/packages/screeb-sdk-angular/docs/classes/Screeb.md @@ -353,7 +353,7 @@ ___ ### init -▸ **init**(`websiteId`, `userId?`, `userProperties?`, `hooks?`): `Promise`<`unknown`\> +▸ **init**(`websiteId`, `userId?`, `userProperties?`, `hooks?`, `language?`): `Promise`<`unknown`\> Initializes Screeb tag. @@ -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 @@ -387,6 +388,7 @@ this.screeb.init( version: "1.0.0", onReady: (payload) => console.log("Screeb SDK is ready!", payload), }, + "en" ); ``` @@ -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. @@ -448,6 +450,7 @@ Starts a survey by its ID. | `allowMultipleResponses` | `boolean` | | `hiddenFields` | `PropertyRecord` | | `hooks?` | `Hooks` | +| `language?` | `string` | #### Returns @@ -467,6 +470,7 @@ this.screeb.surveyStart( version: "1.0.0", onSurveyShowed: (payload) => console.log("Survey showed", payload), }, + "en" ); ``` diff --git a/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts b/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts index af604fa..3cea0fb 100644 --- a/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts +++ b/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts @@ -315,6 +315,7 @@ export class Screeb { * version: "1.0.0", * onSurveyShowed: (payload) => console.log("Survey showed", payload), * }, + * "en" * ); * ``` */ @@ -322,7 +323,8 @@ export class Screeb { surveyId: string, allowMultipleResponses: boolean, hiddenFields: _Screeb.PropertyRecord, - hooks?: _Screeb.Hooks + hooks?: _Screeb.Hooks, + language?: string ) { await this.ensureScreeb("surveyStart"); @@ -330,7 +332,8 @@ export class Screeb { surveyId, allowMultipleResponses, hiddenFields, - hooks + hooks, + language ); } @@ -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 @@ -404,6 +408,7 @@ export class Screeb { * version: "1.0.0", * onReady: (payload) => console.log("Screeb SDK is ready!", payload), * }, + * "en" * ); * ``` */ @@ -411,13 +416,20 @@ export class Screeb { 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 + ); } /** diff --git a/packages/screeb-sdk-browser/docs/README.md b/packages/screeb-sdk-browser/docs/README.md index 4e6aad2..4317ca2 100644 --- a/packages/screeb-sdk-browser/docs/README.md +++ b/packages/screeb-sdk-browser/docs/README.md @@ -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. @@ -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 @@ -738,6 +739,7 @@ Screeb.init( version: "1.0.0", onReady: (payload) => console.log("Screeb SDK is ready!", payload), }, + "en" ); ``` @@ -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. @@ -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 @@ -846,6 +849,7 @@ Screeb.surveyStart( version: "1.0.0", onSurveyShowed: (payload) => console.log("Survey showed", payload), }, + "en" ); ``` diff --git a/packages/screeb-sdk-browser/src/index.ts b/packages/screeb-sdk-browser/src/index.ts index 593d75d..42fb99c 100644 --- a/packages/screeb-sdk-browser/src/index.ts +++ b/packages/screeb-sdk-browser/src/index.ts @@ -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"; @@ -118,6 +120,7 @@ export const load = (options: ScreebOptions = {}) => * version: "1.0.0", * onReady: (payload) => console.log("Screeb SDK is ready!", payload), * }, + * "en" * ); * ``` */ @@ -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 = { @@ -139,6 +149,10 @@ export const init = ( }; } + if (language) { + identityObject = { ...identityObject, language }; + } + return callScreebCommand("init", websiteId, identityObject); }; @@ -426,6 +440,7 @@ export const surveyClose = () => callScreebCommand("survey.close"); * version: "1.0.0", * onSurveyShowed: (payload) => console.log("Survey showed", payload), * }, + * "en" * ); * ``` */ @@ -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, }); diff --git a/packages/screeb-sdk-react/docs/README.md b/packages/screeb-sdk-react/docs/README.md index 20b82c8..6e2f68f 100644 --- a/packages/screeb-sdk-react/docs/README.md +++ b/packages/screeb-sdk-react/docs/README.md @@ -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. @@ -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 @@ -398,7 +400,8 @@ init( plan: '', last_seen_at: new Date(), authenticated: true - } + }, + "en" ); ``` @@ -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. | @@ -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. @@ -528,6 +532,8 @@ Starts a survey by its ID. | `surveyId` | `string` | | `allowMultipleResponses` | `boolean` | | `hiddenFields` | `PropertyRecord` | +| `hooks` | `Hooks` | +| `language` | `string` | ##### Returns diff --git a/packages/screeb-sdk-react/src/provider.tsx b/packages/screeb-sdk-react/src/provider.tsx index d00cc88..a25b78c 100644 --- a/packages/screeb-sdk-react/src/provider.tsx +++ b/packages/screeb-sdk-react/src/provider.tsx @@ -17,6 +17,7 @@ export const ScreebProvider: React.FC< userId, userProperties, hooks, + language, children, shouldLoad = !isSSR, autoInit = false, @@ -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; } @@ -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", @@ -198,6 +200,7 @@ export const ScreebProvider: React.FC< allowMultipleResponses: boolean, hiddenFields: Screeb.PropertyRecord, hooks?: Screeb.Hooks, + language?: string, ) => await ensureScreeb("surveyStart", () => Screeb.surveyStart( @@ -205,6 +208,7 @@ export const ScreebProvider: React.FC< allowMultipleResponses, hiddenFields, hooks, + language, ), ), [], diff --git a/packages/screeb-sdk-react/src/types.ts b/packages/screeb-sdk-react/src/types.ts index 866ccb6..4abcf6d 100644 --- a/packages/screeb-sdk-react/src/types.ts +++ b/packages/screeb-sdk-react/src/types.ts @@ -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; }; /** @@ -266,6 +268,7 @@ export type IdentityResetFunction = () => Promise; * - 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 @@ -280,7 +283,8 @@ export type IdentityResetFunction = () => Promise; * plan: '', * last_seen_at: new Date(), * authenticated: true - * } + * }, + * "en" * ); * ``` */ @@ -288,6 +292,8 @@ export type InitFunction = ( websiteId: string, userId?: string, userProperties?: PropertyRecord, + hooks?: Hooks, + language?: string, ) => Promise; /** @@ -339,6 +345,8 @@ export type SurveyStartFunction = ( surveyId: string, allowMultipleResponses: boolean, hiddenFields: PropertyRecord, + hooks: Hooks, + language: string, ) => Promise; /**