@kompasid/lit-web-components 0.4.0 → 0.4.1

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.
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import { html, css, LitElement } from 'lit'
2
+ import { html, css, LitElement, nothing } from 'lit'
3
3
  import { property, customElement, state } from 'lit/decorators.js'
4
4
  import { TWStyles } from '../../../tailwind/tailwind.js'
5
5
  import { deviceType } from '../../utils/deviceType.js'
6
+ import { formatRupiah } from '../../utils/formatRupiah.js'
6
7
 
7
8
  @customElement('kompasid-paywall-video')
8
9
  export class KompasPaywallVideo extends LitElement {
@@ -28,11 +29,9 @@ export class KompasPaywallVideo extends LitElement {
28
29
  * prop page_domain = Page Domain
29
30
  * prop metered_wall_type = The type of Metered Wall
30
31
  * prop metered_wall_balance = The balance of their metered wall
32
+ * prop type = The type of video paywall
31
33
  */
32
34
 
33
- @state() private subscriptionUrl: string =
34
- 'https://www.kompas.id/berlangganan'
35
-
36
35
  @property({ type: Boolean }) isLogin = false
37
36
  @property({ type: String }) paywall_location = ''
38
37
  @property({ type: String }) paywall_subscription_package = ''
@@ -49,24 +48,41 @@ export class KompasPaywallVideo extends LitElement {
49
48
  @property({ type: String }) tracker_page_domain = ''
50
49
  @property({ type: String }) tracker_metered_wall_type = ''
51
50
  @property({ type: Number }) tracker_metered_wall_balance = 0
51
+ @property({ type: String }) type: 'article' | 'homepage' = 'article'
52
+
53
+ /**
54
+ * State
55
+ */
56
+
57
+ @state() private subscriptionUrl: string =
58
+ 'https://www.kompas.id/berlangganan'
59
+ @state() private checkoutHost: string = 'https://checkoutv2.kompas.id'
60
+
61
+ /**
62
+ * Component
63
+ */
52
64
 
53
- private isLoginComponent() {
65
+ private regulerRegistrationSection() {
54
66
  return html`
55
- <div>
56
- ${this.sendDataLayeronBerlangganan()}
57
- <h5
58
- class="leading-6 text-white text-center text-base md:text-xl max-w-2xl"
59
- >
60
- Akses konten premium Anda bulan ini sudah habis. Aktifkan langganan
61
- untuk akses tanpa batas, mulai dari
62
- <span class="font-bold">Rp50.000/bulan.</span>
63
- </h5>
64
- <div class="flex justify-between mt-4">
67
+ <div
68
+ class="flex flex-col text-white text-sm md:text-base font-sans items-center justify-center"
69
+ >
70
+ <div>
65
71
  <button
66
- @click=${() => this.redirectToBerlangganan()}
67
- class="bg-green-500 rounded px-4 py-1.5 text-sm text-white font-bold"
72
+ @click=${() => this.redirectToRegister('Daftar')}
73
+ class="text-blue-300 font-bold"
68
74
  >
69
- Berlangganan
75
+ Daftar
76
+ </button>
77
+ <span> untuk akses konten gratis.</span>
78
+ </div>
79
+ <div>
80
+ <span>Sudah punya akun? </span>
81
+ <button
82
+ @click=${this.redirectToLogin}
83
+ class="text-blue-300 font-bold"
84
+ >
85
+ Masuk<span class="text-white font-normal">.</span>
70
86
  </button>
71
87
  </div>
72
88
  </div>
@@ -75,73 +91,88 @@ export class KompasPaywallVideo extends LitElement {
75
91
 
76
92
  private defaultComponent() {
77
93
  return html`
78
- <div>
79
- ${this.sendDataLayeronNonLogin()} ${this.sendDataLayeronBerlangganan()}
94
+ <div class="flex font-sans flex-col items-center space-y-2 md:space-y-4">
95
+ ${this.sendDataLayeronNonLogin()} ${this.sendDataLayerPaywallViewed()}
80
96
  <h5
81
- class="leading-6 text-white text-center text-base md:text-xl max-w-xl"
97
+ class="leading-5 md:leading-6 w-[296px] md:w-[400px] text-white text-center text-base mb-2 md:mb-0 ${!this
98
+ .isLogin &&
99
+ !this.isArticle &&
100
+ 'mb-0'} md:text-xl max-w-xl"
82
101
  >
83
- Langganan untuk akses ke seluruh konten premium, mulai dari
84
- <span class="font-bold">Rp50.000/bulan.</span>
102
+ ${this.isArticle
103
+ ? 'Langganan untuk lanjut menonton video'
104
+ : 'Langganan sekarang untuk akses seluruh konten Kompas.id'}
85
105
  </h5>
86
- <div class="flex justify-center mt-4 space-x-3">
87
- <button
88
- @click=${() => this.redirectToRegister('Masuk')}
89
- class="rounded text-sm text-white px-4 py-1.5 ring-1 ring-grey-100"
90
- >
91
- Masuk
92
- </button>
93
- <button
94
- @click=${() => this.redirectToBerlangganan()}
95
- class="bg-green-500 rounded px-4 py-1.5 text-sm text-white font-bold"
96
- >
97
- Berlangganan
98
- </button>
99
- </div>
100
- <p
101
- class="text-center text-sm leading-4 text-white mt-6 max-w-xs md:max-w-none"
106
+ <button
107
+ @click=${this.redirectToSelectedPackage}
108
+ class="bg-green-500 rounded md:rounded-lg h-8 md:h-12 px-4 md:px-6 text-sm md:text-lg text-white font-bold leading-[18px]"
102
109
  >
103
- Dapatkan 5 konten premium gratis tiap bulan!
104
- <button
105
- @click=${() => this.redirectToRegister('Coba Sekarang')}
106
- target="_blank"
107
- class="text-blue-300 font-bold cursor-pointer"
108
- >
109
- Coba Sekarang
110
- </button>
111
- </p>
110
+ Langganan ${formatRupiah(this.showPackage.price)}
111
+ /${this.generateCopyDuration(this.showPackage.durationType)}
112
+ </button>
113
+ <button
114
+ @click=${this.redirectToBerlangganan}
115
+ class="text-sm md:text-lg leading-[22px] text-white font-bold underline ${!this
116
+ .isLogin && this.isArticle
117
+ ? 'pb-3'
118
+ : 'pb-2'} md:pb-4"
119
+ >
120
+ Paket Lainnya
121
+ </button>
122
+ ${!this.isLogin ? this.regulerRegistrationSection() : nothing}
112
123
  </div>
113
124
  `
114
125
  }
115
126
 
116
- private sendDataLayeronNonLogin = (): void => {
117
- window.dataLayer.push({
118
- event: 'registrationOfferimppression',
119
- interface: deviceType(),
120
- })
121
- }
127
+ /**
128
+ * Data Layer
129
+ */
122
130
 
123
- private sendDataLayeronBerlangganan = (): void => {
124
- window.dataLayer.push({
125
- event: 'paywall_viewed',
131
+ private sendDataLayer(event: string): void {
132
+ const baseData = {
133
+ event,
126
134
  paywall_location: this.paywall_location,
127
- paywall_subscription_package: this.paywall_subscription_package,
128
- paywall_subscription_id: this.paywall_subscription_id,
129
- paywall_subscription_price: this.paywall_subscription_price,
130
- paywall_position: this.paywall_position,
131
- page_type: this.tracker_page_type,
132
- content_id: this.tracker_content_id,
133
- content_title: this.tracker_content_title,
134
- content_categories: this.tracker_content_categories,
135
- content_type: this.tracker_content_type,
135
+ paywall_subscription_package:
136
+ this.paywall_subscription_package || this.showPackage.title,
137
+ paywall_subscription_id:
138
+ this.paywall_subscription_id || this.showPackage.id,
139
+ paywall_subscription_price:
140
+ this.paywall_subscription_price || this.showPackage.price,
141
+ paywall_position: this.paywall_position || this.showPackage.position,
136
142
  user_type: this.tracker_user_type,
137
143
  subscription_status: this.tracker_subscription_status,
138
144
  page_domain: this.tracker_page_domain || 'Kompas.id',
139
145
  metered_wall_type: this.tracker_metered_wall_type || 'HP',
140
146
  metered_wall_balance: this.tracker_metered_wall_balance,
141
- })
147
+ }
148
+
149
+ const data = this.isArticle
150
+ ? {
151
+ ...baseData,
152
+ page_type: this.tracker_page_type,
153
+ content_id: this.tracker_content_id,
154
+ content_title: this.tracker_content_title,
155
+ content_categories: this.tracker_content_categories,
156
+ content_type: this.tracker_content_type,
157
+ }
158
+ : baseData
159
+
160
+ window.dataLayer.push(data)
161
+ }
162
+
163
+ private sendDataLayerPaywallViewed(): void {
164
+ this.sendDataLayer('paywall_viewed')
165
+ }
166
+
167
+ private sendDataLayerSubscribeButtonClicked(): void {
168
+ this.sendDataLayer('subscribe_button_clicked')
169
+ }
170
+
171
+ private sendDataLayerOtherPackagesClicked(): void {
172
+ this.sendDataLayer('other_packages_clicked')
142
173
  }
143
174
 
144
- private sendDataLayeronButtonLogin = (triggerClick: string): void => {
175
+ private sendDataLayeronButtonLogin(triggerClick: string): void {
145
176
  window.dataLayer.push({
146
177
  event: 'registrationOfferClick',
147
178
  interface: deviceType(),
@@ -149,46 +180,89 @@ export class KompasPaywallVideo extends LitElement {
149
180
  })
150
181
  }
151
182
 
152
- private sendDataLayeronButtonBerlangganan = (): void => {
183
+ private sendDataLayeronNonLogin(): void {
153
184
  window.dataLayer.push({
154
- event: 'subscribe_button_clicked',
155
- paywall_location: this.paywall_location,
156
- paywall_subscription_package: this.paywall_subscription_package,
157
- paywall_subscription_id: this.paywall_subscription_id,
158
- paywall_subscription_price: this.paywall_subscription_price,
159
- paywall_position: this.paywall_position,
160
- page_type: this.tracker_page_type,
161
- content_id: this.tracker_content_id,
162
- content_title: this.tracker_content_title,
163
- content_categories: this.tracker_content_categories,
164
- content_type: this.tracker_content_type,
165
- user_type: this.tracker_user_type,
166
- subscription_status: this.tracker_subscription_status,
167
- page_domain: this.tracker_page_domain || 'Kompas.id',
168
- metered_wall_type: this.tracker_metered_wall_type || 'HP',
169
- metered_wall_balance: this.tracker_metered_wall_balance,
185
+ event: 'registrationOfferimppression',
186
+ interface: deviceType(),
170
187
  })
171
188
  }
172
189
 
190
+ /**
191
+ * Getter
192
+ */
193
+
194
+ get isArticle() {
195
+ return this.type === 'article'
196
+ }
197
+
198
+ // temporary mocking data package for component and dataLayer
199
+ get showPackage() {
200
+ return {
201
+ duration: 1,
202
+ durationType: 3,
203
+ id: '9802035',
204
+ link: 'kdp?productId=9802035&referrer=https%3A%2F%2Fwww.kompas.cloud%2Fberlangganan',
205
+ price: 50000,
206
+ position: 1,
207
+ title: 'Kompas Digital Premium 1 Bulan',
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Logic Function
213
+ */
214
+
173
215
  private redirectToRegister(triggerClick: string): void {
174
216
  this.sendDataLayeronButtonLogin(triggerClick)
175
217
  const registerHost: string = 'https://account.kompas.id/register'
176
218
  const nextParams: string = encodeURIComponent(window.location.href)
177
- const directUrlRegister: string = `${registerHost}?next=${nextParams}?status=sukses_login&status_login=login`
219
+ const directUrlRegister: string = `${registerHost}?next=${nextParams}?status=sukses_login&status_login=login&loc=video_paywall`
178
220
  window.open(directUrlRegister, '_blank')
179
221
  }
180
222
 
223
+ private redirectToLogin(): void {
224
+ const loginHost: string = 'https://account.kompas.id/login'
225
+ const nextParams: string = encodeURIComponent(window.location.href)
226
+ const directUrlLogin: string = `${loginHost}?next=${nextParams}&loc=video_paywall`
227
+ window.open(directUrlLogin, '_blank')
228
+ }
229
+
230
+ private redirectToSelectedPackage(): void {
231
+ const url = `${this.checkoutHost}/${this.showPackage.link}&source=${this.type}`
232
+ this.sendDataLayerSubscribeButtonClicked()
233
+ window.open(url, '_blank')
234
+ }
235
+
181
236
  private redirectToBerlangganan(): void {
182
- this.sendDataLayeronButtonBerlangganan()
237
+ this.sendDataLayerOtherPackagesClicked()
183
238
  window.open(this.subscriptionUrl, '_blank')
184
239
  }
185
240
 
241
+ private generateCopyDuration(type: number): string {
242
+ switch (type) {
243
+ case 1:
244
+ return 'hari'
245
+ case 2:
246
+ return 'minggu'
247
+ case 3:
248
+ return 'bulan'
249
+ case 4:
250
+ return 'tahun'
251
+ default:
252
+ return ''
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Render Statement
258
+ */
259
+
186
260
  render() {
187
261
  return html`
188
262
  <div
189
- class="radius absolute z-20 bg-black bg-opacity-50 p-4 top-0 bottom-0 left-0 flex flex-col w-full h-full justify-center items-center"
263
+ class="radius absolute z-20 bg-black bg-opacity-75 p-4 top-0 bottom-0 left-0 flex flex-col w-full h-full justify-center items-center"
190
264
  >
191
- ${this.isLogin ? this.isLoginComponent() : this.defaultComponent()}
265
+ ${this.defaultComponent()}
192
266
  </div>
193
267
  `
194
268
  }
@@ -36,6 +36,7 @@ Contoh Penerapan:
36
36
  | `tracker_page_type` | `tracker_page_type` | prop page_type = Type of the page | `string` | `''` |
37
37
  | `tracker_subscription_status` | `tracker_subscription_status` | prop subscription_status = Status of their subscription | `string` | `''` |
38
38
  | `tracker_user_type` | `tracker_user_type` | prop user_type = Type of user based on their subscription | `string` | `''` |
39
+ | `type` | `type` | prop type = The type of video paywall | `"article" \| "homepage"` | `"article"` |
39
40
 
40
41
  ----------------------------------------------
41
42
 
@@ -0,0 +1,6 @@
1
+ export const formatRupiah = (value: number) => {
2
+ const roundedValue = Math.round(value)
3
+ return `Rp ${roundedValue
4
+ .toString()
5
+ .replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')}`
6
+ }