Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): force language #32

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'. default: browser language. |

#### 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` |
cley44 marked this conversation as resolved.
Show resolved Hide resolved

#### 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'. default: browser language.
*
* @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'. default: browser language. |

#### 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
27 changes: 22 additions & 5 deletions packages/screeb-sdk-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const callScreebCommand: ScreebFunction = (...args) => {
}

return Promise.reject(
"[Screeb] Screeb.load() must be called before any other function.",
"[Screeb] Screeb.load() must be called before any other function."
);
};

Expand Down 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'. default: browser language.
*
* @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 @@ -231,7 +245,7 @@ export const debug = () => callScreebCommand("debug");
*/
export const eventTrack = (
eventName: string,
eventProperties?: PropertyRecord,
eventProperties?: PropertyRecord
) => callScreebCommand("event.track", eventName, eventProperties);

/**
Expand Down Expand Up @@ -320,13 +334,13 @@ export const identityGet = (): Promise<ScreebIdentityGetReturn> =>
export const identityGroupAssign = (
groupName: string,
groupType?: string,
groupProperties?: PropertyRecord,
groupProperties?: PropertyRecord
) =>
callScreebCommand(
"identity.group.assign",
groupType,
groupName,
groupProperties,
groupProperties
);

/**
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'. default: browser language. |

##### 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
Loading
Loading