@streamlayer/feature-gamification 1.11.1 → 1.12.0

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.
@@ -35,7 +35,9 @@ export declare const advertisement: ($slStreamId: GamificationBackground["slStre
35
35
  connect: () => void;
36
36
  hide: (notificationId?: string) => void;
37
37
  show: (advertisementId: string, data?: Awaited<ReturnType<typeof getPromotionDetail>>) => void;
38
- open: () => void;
38
+ open: (options?: {
39
+ fromNotification?: boolean;
40
+ }) => void;
39
41
  markAsViewed: () => void;
40
42
  $store: import("nanostores").MapStore<Advertisement>;
41
43
  };
@@ -50,20 +50,31 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
50
50
  const storage = new AdvertisementStorage();
51
51
  const $store = createMapStore({});
52
52
  const $activeAdvertisement = $activePromotionId($slStreamId, transport);
53
- const open = () => {
54
- $store.setKey('hasNotification', false);
55
- const payload = $store.get();
56
- const id = payload.data?.question.id;
57
- const type = payload.data?.promotion?.type;
58
- if (id) {
59
- eventBus.emit('advertisement', {
60
- action: 'notification-opened',
61
- payload: {
62
- id,
63
- type,
64
- hasBanner: adHasBanner(payload.data),
65
- },
66
- });
53
+ const open = (options) => {
54
+ if (options?.fromNotification) {
55
+ $store.setKey('hasNotification', false);
56
+ const payload = $store.get();
57
+ const id = payload.data?.question.id;
58
+ const type = payload.data?.promotion?.type;
59
+ if (id) {
60
+ eventBus.emit('advertisement', {
61
+ action: 'opened',
62
+ payload: {
63
+ id,
64
+ type,
65
+ hasBanner: adHasBanner(payload.data),
66
+ openedFrom: 'notification',
67
+ },
68
+ });
69
+ eventBus.emit('advertisement', {
70
+ action: 'notification-opened',
71
+ payload: {
72
+ id,
73
+ type,
74
+ hasBanner: adHasBanner(payload.data),
75
+ },
76
+ });
77
+ }
67
78
  }
68
79
  };
69
80
  const markAsViewed = () => {
@@ -76,7 +87,7 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
76
87
  storage.setShowed(id);
77
88
  $store.setKey('isOpened', true);
78
89
  eventBus.emit('advertisement', {
79
- action: 'opened',
90
+ action: 'viewed',
80
91
  payload: {
81
92
  id,
82
93
  type,
@@ -143,6 +154,18 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
143
154
  },
144
155
  skipAnalytics: active.data.question.id === prevActive?.data?.question.id,
145
156
  });
157
+ if (active.data.question.id !== prevActive?.data?.question.id && !storage.isViewed(active.data.question.id)) {
158
+ eventBus.emit('advertisement', {
159
+ action: 'notification-received',
160
+ payload: {
161
+ id: active.data.question.id,
162
+ type: active.data.promotion.type,
163
+ hasNotification: true,
164
+ hasBanner: adHasBanner(active.data),
165
+ isViewed: false,
166
+ },
167
+ });
168
+ }
146
169
  }
147
170
  if (!active?.data && prevActive?.data) {
148
171
  eventBus.emit('advertisement', {
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-gamification",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "peerDependencies": {
5
5
  "@bufbuild/protobuf": "^1.10.0",
6
6
  "@fastify/deepmerge": "^2.0.0",
7
7
  "@streamlayer/sl-eslib": "^5.130.0",
8
8
  "nanostores": "^0.10.3",
9
- "@streamlayer/sdk-web-api": "^1.6.12",
10
- "@streamlayer/sdk-web-core": "^1.8.1",
11
- "@streamlayer/sdk-web-logger": "^1.0.33",
12
- "@streamlayer/sdk-web-notifications": "^1.2.12",
13
- "@streamlayer/sdk-web-interfaces": "^1.3.1",
14
- "@streamlayer/sdk-web-storage": "^1.0.33",
15
- "@streamlayer/sdk-web-types": "^1.8.6"
9
+ "@streamlayer/sdk-web-api": "^1.6.13",
10
+ "@streamlayer/sdk-web-core": "^1.8.2",
11
+ "@streamlayer/sdk-web-interfaces": "^1.4.0",
12
+ "@streamlayer/sdk-web-logger": "^1.0.34",
13
+ "@streamlayer/sdk-web-storage": "^1.0.34",
14
+ "@streamlayer/sdk-web-notifications": "^1.2.13",
15
+ "@streamlayer/sdk-web-types": "^1.8.7"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tslib": "^2.7.0"