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

Web SDK Release v1.6.9 #182

Merged
merged 10 commits into from
Dec 6, 2023
Merged
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.6.9] - 6 Dec, 2023
- Adds public method markReadInboxMessagesForIds.
- Adds public method setLibrary to set the Flutter version.
- Fixes a bug related to Web Inbox scroll.
- Triggers an event to manage inline script errors related to Content Security Policy.

## [1.6.8] - 9 Nov, 2023
- Adds handling for email unsubscribe.

Expand Down
100 changes: 69 additions & 31 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.6.8",
"version": "1.6.9",
"description": "",
"main": "clevertap.js",
"scripts": {
Expand Down
25 changes: 21 additions & 4 deletions src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ export default class CleverTap {
return this.#account.finalTargetDomain
}

this.setLibrary = (libName, libVersion) => {
$ct.flutterVersion = { [libName]: libVersion }
}

// Set the Signed Call sdk version and fire request
this.setSCSDKVersion = (ver) => {
this.#account.scSDKVersion = ver
Expand Down Expand Up @@ -263,9 +267,11 @@ export default class CleverTap {
const el = document.querySelector('ct-web-inbox').shadowRoot.getElementById(messageId)
if (el !== null) { el.shadowRoot.getElementById('unreadMarker').style.display = 'none' }
messages[messageId].viewed = 1
var counter = parseInt(document.getElementById('unviewedBadge').innerText) - 1
document.getElementById('unviewedBadge').innerText = counter
document.getElementById('unviewedBadge').style.display = counter > 0 ? 'flex' : 'none'
if (document.getElementById('unviewedBadge')) {
var counter = parseInt(document.getElementById('unviewedBadge').innerText) - 1
document.getElementById('unviewedBadge').innerText = counter
document.getElementById('unviewedBadge').style.display = counter > 0 ? 'flex' : 'none'
}
window.clevertap.renderNotificationViewed({ msgId: messages[messageId].wzrk_id, pivotId: messages[messageId].pivotId })
$ct.inbox.unviewedCounter--
delete $ct.inbox.unviewedMessages[messageId]
Expand All @@ -275,6 +281,15 @@ export default class CleverTap {
}
}

/* Mark Message as Read. messageIds should be a an array of string */
this.markReadInboxMessagesForIds = (messageIds) => {
if (Array.isArray(messageIds)) {
for (var id = 0; id < messageIds.length; id++) {
this.markReadInboxMessage(messageIds[id])
}
}
}

/* Mark all messages as read
- Get the count of unread messages, update unread marker style
- renderNotificationViewed, update the badge count and style
Expand All @@ -300,6 +315,8 @@ export default class CleverTap {
}
}

this.toggleInbox = (e) => $ct.inbox?.toggleInbox(e)

// method for notification viewed
this.renderNotificationViewed = (detail) => {
processNotificationEvent(NOTIFICATION_VIEWED, detail)
Expand Down Expand Up @@ -689,7 +706,7 @@ export default class CleverTap {
}
let proto = document.location.protocol
proto = proto.replace(':', '')
data.af = { lib: 'web-sdk-v$$PACKAGE_VERSION$$', protocol: proto }
data.af = { lib: 'web-sdk-v$$PACKAGE_VERSION$$', protocol: proto, ...$ct.flutterVersion }
pageLoadUrl = addToURL(pageLoadUrl, 'type', 'page')
pageLoadUrl = addToURL(pageLoadUrl, 'd', compressData(JSON.stringify(data), this.#logger))

Expand Down
28 changes: 19 additions & 9 deletions src/modules/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,30 @@ export default class ProfileHandler extends Array {
* Adds array or single value against a key/property in profile object
*/
_handleMultiValueAdd (propKey, propVal, command) {
// Initialize array
var array = []

// Check if globalProfileMap is null, initialize if needed
if ($ct.globalProfileMap == null) {
$ct.globalProfileMap = StorageManager.readFromLSorCookie(PR_COOKIE) ?? {}
$ct.globalProfileMap = StorageManager.readFromLSorCookie(PR_COOKIE) || {}
}
// if the value to be set is either string or number

// Check if the value to be set is either string or number
if (typeof propVal === 'string' || typeof propVal === 'number') {
if ($ct.globalProfileMap.hasOwnProperty(propKey)) {
array = $ct.globalProfileMap[propKey]
typeof propVal === 'number' ? array.push(propVal) : array.push(propVal.toLowerCase())
// Push the value to the array in a more concise way
array.push(typeof propVal === 'number' ? propVal : propVal.toLowerCase())
} else {
$ct.globalProfileMap[propKey] = propVal
}
// if propVal is an array
} else {
// Check if propVal is an array
if ($ct.globalProfileMap.hasOwnProperty(propKey)) {
array = $ct.globalProfileMap[propKey]
array = Array.isArray($ct.globalProfileMap[propKey]) ? $ct.globalProfileMap[propKey] : [$ct.globalProfileMap[propKey]]
}
/**
* checks for case sensitive inputs and filters the same ones
*/

// Check for case-sensitive inputs and filter the same ones
for (var i = 0; i < propVal.length; i++) {
if (typeof propVal[i] === 'number' && !array.includes(propVal[i])) {
array.push(propVal[i])
Expand All @@ -228,12 +232,18 @@ export default class ProfileHandler extends Array {
} else if ((typeof propVal[i] === 'number' && array.includes(propVal[i])) || (typeof propVal[i] === 'string' && array.includes(propVal[i].toLowerCase()))) {
console.error('Values already included')
} else {
console.error('array supports only string or number type values')
console.error('Array supports only string or number type values')
}
}

// Update globalProfileMap with the array
$ct.globalProfileMap[propKey] = array
}

// Save to local storage or cookie
StorageManager.saveToLSorCookie(PR_COOKIE, $ct.globalProfileMap)

// Call the sendMultiValueData function
this.sendMultiValueData(propKey, propVal, command)
}

Expand Down
8 changes: 7 additions & 1 deletion src/modules/web-inbox/WebInbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Inbox extends HTMLElement {
}

isInboxOpen = false
isInboxFromFlutter = false
selectedCategory = null
unviewedMessages = {}
unviewedCounter = 0
Expand Down Expand Up @@ -377,7 +378,11 @@ export class Inbox extends HTMLElement {
}
}
} else if (this.inboxSelector.contains(e.target) || this.isInboxOpen) {
this.toggleInbox(e)
if (this.isInboxFromFlutter) {
this.isInboxFromFlutter = false
} else {
this.toggleInbox(e)
}
}
}
})()
Expand Down Expand Up @@ -420,6 +425,7 @@ export class Inbox extends HTMLElement {
// create a separte fn fro refactoring
toggleInbox (e) {
this.isInboxOpen = !this.isInboxOpen
this.isInboxFromFlutter = !!e?.rect
if (this.isInboxOpen) {
this.inboxCard.scrollTop = 0
!this.isPreview && this.deleteExpiredAndGetUnexpiredMsgs()
Expand Down
Loading