Skip to content

Commit

Permalink
Merge pull request #321 from CleverTap/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
singhkunal2050 authored Dec 18, 2024
2 parents c8206f1 + 9d56900 commit 327454c
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 16 deletions.
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

### Changes

Describe the key changes in this PR with the Jira Issue reference

### Changes to Public Facing API if any

Please list the impact on the public facing API if any

### How Has This Been Tested?

Describe the testing approach and any relevant configurations (e.g., environment, platform)

### Checklist

- [ ] Code compiles without errors
- [ ] Version Bump added to package.json & CHANGELOG.md
- [ ] All tests pass
- [ ] Build process is successful
- [ ] Documentation has been updated (if needed)
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

0 comments on commit 327454c

Please sign in to comment.