@streamlayer/feature-gamification 0.33.1 → 0.33.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/gamification.js +1 -1
- package/lib/onboarding.js +71 -42
- package/lib/storage.d.ts +2 -0
- package/lib/storage.js +9 -0
- package/package.json +2 -2
package/lib/gamification.js
CHANGED
|
@@ -75,7 +75,7 @@ export class Gamification extends AbstractFeature {
|
|
|
75
75
|
*/
|
|
76
76
|
this.background.activeQuestionId.listen((question) => {
|
|
77
77
|
const onboardingStatus = this.onboardingStatus.$store.get();
|
|
78
|
-
if (question && question.data && onboardingStatus) {
|
|
78
|
+
if (question && question.data && onboardingStatus && onboardingStatus !== OnboardingStatus.Unset) {
|
|
79
79
|
if (question.data.question?.id !== undefined &&
|
|
80
80
|
question.data.question.notification !== undefined &&
|
|
81
81
|
question.data.question?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
|
package/lib/onboarding.js
CHANGED
|
@@ -25,7 +25,7 @@ export const onboarding = (service, background, transport, notifications) => {
|
|
|
25
25
|
const showOnboardingInApp = () => {
|
|
26
26
|
const { inplayGame } = service.featureSettings.get();
|
|
27
27
|
const notificationId = background.getCurrentSessionId({ prefix: 'onboarding' });
|
|
28
|
-
if (inplayGame
|
|
28
|
+
if (inplayGame) {
|
|
29
29
|
notifications.add({
|
|
30
30
|
type: NotificationType.ONBOARDING,
|
|
31
31
|
id: notificationId,
|
|
@@ -39,70 +39,99 @@ export const onboarding = (service, background, transport, notifications) => {
|
|
|
39
39
|
questionType: QuestionType.UNSET,
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
41
|
// @ts-ignore
|
|
42
|
-
onboarding: {
|
|
42
|
+
onboarding: {
|
|
43
|
+
...inplayGame,
|
|
44
|
+
instantOpen: !storage.getOnboardingInstantOpen({
|
|
45
|
+
userId: background.userId.get() || '',
|
|
46
|
+
organizationId: background.organizationId.get() || '',
|
|
47
|
+
eventId: background.slStreamId.get() || '',
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
43
50
|
},
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
53
|
};
|
|
47
54
|
$store.subscribe((onboardingStatus) => {
|
|
48
|
-
if (onboardingStatus === OnboardingStatus.
|
|
55
|
+
if (onboardingStatus === OnboardingStatus.Unset) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (onboardingStatus === OnboardingStatus.Optional || onboardingStatus === OnboardingStatus.Required) {
|
|
49
59
|
showOnboardingInApp();
|
|
50
60
|
}
|
|
51
61
|
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
52
62
|
background.activeQuestionId.invalidate();
|
|
53
63
|
}
|
|
64
|
+
storage.setOnboardingInstantOpen({
|
|
65
|
+
userId: background.userId.get() || '',
|
|
66
|
+
organizationId: background.organizationId.get() || '',
|
|
67
|
+
eventId: background.slStreamId.get() || '',
|
|
68
|
+
});
|
|
54
69
|
});
|
|
55
70
|
/**
|
|
56
71
|
* check onboarding status, sync with browser cache
|
|
57
72
|
* retrieve onboarding settings from api
|
|
58
73
|
*/
|
|
59
74
|
const onboardingProcess = async () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const onboardingStatus = storage.getOnboardingStatus({
|
|
66
|
-
userId,
|
|
67
|
-
organizationId: background.organizationId.get() || '',
|
|
68
|
-
eventId: background.slStreamId.get() || '',
|
|
69
|
-
});
|
|
70
|
-
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
71
|
-
$store.set(OnboardingStatus.Completed);
|
|
72
|
-
}
|
|
73
|
-
const moderation = await background.moderation.getValue();
|
|
74
|
-
if ($store.get() === OnboardingStatus.Completed) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const onboardingEnabled = !!(moderation?.options?.onboardingEnabled && service.featureSettings.get().inplayGame?.onboarding?.completed);
|
|
78
|
-
const optIn = !!service.featureSettings.get().inplayGame?.titleCard?.optIn;
|
|
79
|
-
if (onboardingEnabled) {
|
|
80
|
-
if (optIn) {
|
|
81
|
-
$store.set(OnboardingStatus.Required);
|
|
75
|
+
try {
|
|
76
|
+
const userId = background.userId.get();
|
|
77
|
+
if (!userId) {
|
|
78
|
+
$store.set(OnboardingStatus.Unset);
|
|
79
|
+
return;
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const onboardingStatus = storage.getOnboardingStatus({
|
|
82
|
+
userId,
|
|
83
|
+
organizationId: background.organizationId.get() || '',
|
|
84
|
+
eventId: background.slStreamId.get() || '',
|
|
85
|
+
});
|
|
86
|
+
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
87
|
+
$store.set(OnboardingStatus.Completed);
|
|
85
88
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
const moderation = await background.moderation.getValue();
|
|
90
|
+
if ($store.get() === OnboardingStatus.Completed) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const onboardingEnabled = !!moderation?.options?.onboardingEnabled;
|
|
94
|
+
const optIn = !!service.featureSettings.get().inplayGame?.titleCard?.optIn;
|
|
95
|
+
if (moderation === undefined || service.featureSettings.get() === undefined) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (onboardingEnabled) {
|
|
99
|
+
if (optIn) {
|
|
100
|
+
$store.set(OnboardingStatus.Required);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
$store.set(OnboardingStatus.Optional);
|
|
104
|
+
}
|
|
90
105
|
}
|
|
91
106
|
else {
|
|
92
|
-
|
|
107
|
+
if (optIn) {
|
|
108
|
+
$store.set(OnboardingStatus.Unavailable);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
$store.set(OnboardingStatus.Disabled);
|
|
112
|
+
}
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
background.userId.subscribe((userId) => {
|
|
98
|
-
if (userId) {
|
|
99
|
-
void onboardingProcess();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
background.moderation.subscribe((value) => {
|
|
103
|
-
if (value.data) {
|
|
104
|
-
void onboardingProcess();
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error(error);
|
|
105
117
|
}
|
|
118
|
+
};
|
|
119
|
+
void onboardingProcess().then(() => {
|
|
120
|
+
background.userId.listen((userId) => {
|
|
121
|
+
if (userId) {
|
|
122
|
+
void onboardingProcess();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
background.moderation.listen((value) => {
|
|
126
|
+
if (value.data) {
|
|
127
|
+
void onboardingProcess();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
service.featureSettings.listen((value) => {
|
|
131
|
+
if (value) {
|
|
132
|
+
void onboardingProcess();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
106
135
|
});
|
|
107
136
|
const submitInplay = async () => {
|
|
108
137
|
const eventId = background.slStreamId.get();
|
package/lib/storage.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export declare class GamificationStorage extends Storage {
|
|
|
9
9
|
constructor();
|
|
10
10
|
saveOnboardingStatus: ({ userId, eventId, organizationId }: UserProps, status: OnboardingStatus) => void;
|
|
11
11
|
getOnboardingStatus: ({ userId, eventId, organizationId }: UserProps) => string | undefined;
|
|
12
|
+
setOnboardingInstantOpen: ({ userId, eventId, organizationId }: UserProps) => void;
|
|
13
|
+
getOnboardingInstantOpen: ({ userId, eventId, organizationId }: UserProps) => string | null;
|
|
12
14
|
}
|
|
13
15
|
export {};
|
package/lib/storage.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Storage } from '@streamlayer/sdk-web-storage';
|
|
|
2
2
|
var KEY_PREFIX;
|
|
3
3
|
(function (KEY_PREFIX) {
|
|
4
4
|
KEY_PREFIX["ONBOARDING"] = "onboarding";
|
|
5
|
+
KEY_PREFIX["ONBOARDING_IO"] = "onboarding_io";
|
|
5
6
|
})(KEY_PREFIX || (KEY_PREFIX = {}));
|
|
6
7
|
export class GamificationStorage extends Storage {
|
|
7
8
|
constructor() {
|
|
@@ -13,4 +14,12 @@ export class GamificationStorage extends Storage {
|
|
|
13
14
|
getOnboardingStatus = ({ userId, eventId, organizationId }) => {
|
|
14
15
|
return this.read(KEY_PREFIX.ONBOARDING, organizationId, userId, eventId);
|
|
15
16
|
};
|
|
17
|
+
setOnboardingInstantOpen = ({ userId, eventId, organizationId }) => {
|
|
18
|
+
const key = this.generateKey([KEY_PREFIX.ONBOARDING_IO, organizationId, userId, eventId]);
|
|
19
|
+
window.sessionStorage.setItem(key, 'true');
|
|
20
|
+
};
|
|
21
|
+
getOnboardingInstantOpen = ({ userId, eventId, organizationId }) => {
|
|
22
|
+
const key = this.generateKey([KEY_PREFIX.ONBOARDING_IO, organizationId, userId, eventId]);
|
|
23
|
+
return window.sessionStorage.getItem(key);
|
|
24
|
+
};
|
|
16
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
6
|
"@streamlayer/sl-eslib": "^5.61.1",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@streamlayer/sdk-web-core": "^0.0.1",
|
|
11
11
|
"@streamlayer/sdk-web-interfaces": "^0.18.21",
|
|
12
12
|
"@streamlayer/sdk-web-logger": "^0.0.1",
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^0.0.
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.0.6",
|
|
14
14
|
"@streamlayer/sdk-web-storage": "^0.0.4",
|
|
15
15
|
"@streamlayer/sdk-web-types": "^0.1.0"
|
|
16
16
|
},
|