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

fixed soft prompt bug #320

Merged
merged 5 commits into from
Dec 16, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.11.13] 12th Dec, 2024
- Fixed web push soft prompt bug

## [1.11.12] 11th Dec, 2024
- Initialize Web Inbox on document readyState complete

Expand Down
35 changes: 28 additions & 7 deletions clevertap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clevertap.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clevertap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clevertap-web-sdk",
"version": "1.11.12",
"version": "1.11.13",
"description": "",
"main": "clevertap.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default class NotificationHandler extends Array {
}

enable (options = {}) {
const { swPath } = options
enablePush(this.#logger, this.#account, this.#request, swPath)
const { swPath, skipDialog } = options
enablePush(this.#logger, this.#account, this.#request, swPath, skipDialog)
}

_processOldValues () {
Expand Down
29 changes: 25 additions & 4 deletions src/modules/webPushPrompt/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const processWebPushConfig = (webPushConfig, logger, request) => {
}
}

export const enablePush = (logger, account, request, customSwPath) => {
export const enablePush = (logger, account, request, customSwPath, skipDialog) => {
const _pushConfig = StorageManager.readFromLSorCookie(WEBPUSH_CONFIG) || {}
$ct.pushConfig = _pushConfig
if (!$ct.pushConfig) {
Expand All @@ -35,6 +35,13 @@ export const enablePush = (logger, account, request, customSwPath) => {
if (customSwPath) { swPath = customSwPath }

notificationHandler = new NotificationHandler({ logger, session: {}, request, account })

if (skipDialog) {
notificationHandler.setApplicationServerKey(appServerKey)
notificationHandler.setUpWebPushNotifications(null, swPath, null, null)
return
}

const { showBox, boxType, showBellIcon, isPreview } = $ct.pushConfig

if (isPreview) {
Expand Down Expand Up @@ -103,13 +110,28 @@ export const createNotificationBox = (configData) => {

setElementPosition(pnCard, style.card.position)

if (!configData.isPreview) {
if ('Notification' in window && Notification !== null) {
if (Notification.permission === 'granted') {
notificationHandler.setApplicationServerKey(appServerKey)
notificationHandler.setUpWebPushNotifications(null, swPath, null, null)
return
} else if (Notification.permission === 'denied') {
return
}
}
}

const now = new Date().getTime() / 1000
const lastNotifTime = StorageManager.getMetaProp('webpush_last_notif_time')
const popupFrequency = content.popupFrequency || 7 * 24 * 60 * 60
const popupFrequency = content.popupFrequency || 7 // number of days

if (!lastNotifTime || now - lastNotifTime >= popupFrequency * 24 * 60 * 60) {
document.body.appendChild(wrapper)
if (!configData.isPreview) { addEventListeners(wrapper) }
if (!configData.isPreview) {
StorageManager.setMetaProp('webpush_last_notif_time', now)
addEventListeners(wrapper)
}
}
}

Expand Down Expand Up @@ -175,7 +197,6 @@ export const addEventListeners = (wrapper) => {
})

secondaryButton.addEventListener('click', () => {
StorageManager.setMetaProp('webpush_last_notif_time', Date.now() / 1000)
removeWrapper()
})
}
Expand Down
Loading