Skip to content

Commit

Permalink
PR comments addressed
Browse files Browse the repository at this point in the history
PR review changes
  • Loading branch information
rohitniyerclevertap committed Feb 26, 2025
1 parent 9b359d1 commit 98ab394
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
37 changes: 24 additions & 13 deletions clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
const OLD_SOFT_PROMPT_SELCTOR_ID = 'wzrk_wrapper';
const NEW_SOFT_PROMPT_SELCTOR_ID = 'pnWrapper';
const POPUP_LOADING = 'WZRK_POPUP_LOADING';
const CUSTOM_HTML_PREVIEW = 'ctCustomHtmlPreview';
const SYSTEM_EVENTS = ['Stayed', 'UTM Visited', 'App Launched', 'Notification Sent', NOTIFICATION_VIEWED, NOTIFICATION_CLICKED];
const KEYS_TO_ENCRYPT = [KCOOKIE_NAME, LRU_CACHE, PR_COOKIE];

Expand Down Expand Up @@ -11990,7 +11991,7 @@
});
document.dispatchEvent(kvPairsEvent);
};
const renderCustomHtml = targetingMsgJson => {
const renderCustomHtml = (targetingMsgJson, logger) => {
const {
display,
wzrk_id: wzrkId,
Expand All @@ -12003,7 +12004,7 @@
const html = details.html;

if (!divId || !html) {
console.error('No div Id or no html found');
logger.error('No div Id or no html found');
return;
}

Expand All @@ -12030,7 +12031,7 @@
retryElement.outerHTML = html;
clearInterval(intervalId);
} else if (++count >= 20) {
console.log("No element present on DOM with divId '".concat(divId, "'."));
logger.log("No element present on DOM with divId '".concat(divId, "'."));
clearInterval(intervalId);
}
}, 500);
Expand All @@ -12057,6 +12058,17 @@
});
document.dispatchEvent(jsonEvent);
};

function handleCustomHtmlPreviewPostMessageEvent(event, logger) {
const eventData = JSON.parse(event.data);
const inAppNotifs = eventData.inapp_notifs;
const msgContent = inAppNotifs[0].msgContent;

if (eventData && msgContent && msgContent.templateType === 'custom-html' && msgContent.type === 5) {
renderCustomHtml(inAppNotifs[0], logger);
}
}

const checkCustomHtmlNativeDisplayPreview = logger => {
const searchParams = new URLSearchParams(window.location.search);
const ctType = searchParams.get('ctActionMode');
Expand All @@ -12065,21 +12077,20 @@
const parentWindow = window.opener;

switch (ctType) {
case 'ctCustomHtmlPreview':
case CUSTOM_HTML_PREVIEW:
if (parentWindow) {
parentWindow.postMessage('ready', '*');
window.addEventListener('message', event => {
const eventData = JSON.parse(event.data);
const inAppNotifs = eventData.inapp_notifs;
const msgContent = inAppNotifs[0].msgContent;

if (eventData && msgContent.templateType === 'custom-html' && msgContent.type === 5) {
renderCustomHtml(inAppNotifs[0]);
}
}, false);
const eventHandler = event => handleCustomHtmlPreviewPostMessageEvent(event, logger);

window.addEventListener('message', eventHandler, false);
}

break;

default:
logger.debug("unknown unknown query param ".concat(ctType));
break;
}
}
};
Expand Down Expand Up @@ -14153,7 +14164,7 @@
} else if (targetNotif.msgContent.type === 4) {
renderVisualBuilder(targetNotif, false);
} else if (targetNotif.msgContent.type === 5) {
renderCustomHtml(targetNotif);
renderCustomHtml(targetNotif, _logger);
} else if (targetNotif.msgContent.type === 6) {
handleJson(targetNotif);
} else {
Expand Down
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 src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class CleverTap {
constructor (clevertap = {}) {
this.#onloadcalled = 0
this._isPersonalisationActive = this._isPersonalisationActive.bind(this)
this.raiseNotificationClicked = () => {}
this.raiseNotificationClicked = () => { }
this.#logger = new Logger(logLevels.INFO)
this.#account = new Account(clevertap.account?.[0], clevertap.region || clevertap.account?.[1], clevertap.targetDomain || clevertap.account?.[2], clevertap.token || clevertap.account?.[3])
encryption.key = clevertap.account?.[0].id
Expand Down
29 changes: 17 additions & 12 deletions src/util/campaignRender/nativeDisplay.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CTWebPersonalisationBanner } from '../web-personalisation/banner'
import { CTWebPersonalisationCarousel } from '../web-personalisation/carousel'
import { CUSTOM_HTML_PREVIEW } from '../constants'

export const renderPersonalisationBanner = (targetingMsgJson) => {
if (customElements.get('ct-web-personalisation-banner') === undefined) {
Expand Down Expand Up @@ -41,15 +42,15 @@ export const handleKVpairCampaign = (targetingMsgJson) => {
document.dispatchEvent(kvPairsEvent)
}

export const renderCustomHtml = (targetingMsgJson) => {
export const renderCustomHtml = (targetingMsgJson, logger) => {
const { display, wzrk_id: wzrkId, wzrk_pivot: wzrkPivot } = targetingMsgJson || {}

const { divId } = display || {}
const details = display.details[0]
const html = details.html

if (!divId || !html) {
console.error('No div Id or no html found')
logger.error('No div Id or no html found')
return
}

Expand All @@ -75,7 +76,7 @@ export const renderCustomHtml = (targetingMsgJson) => {
retryElement.outerHTML = html
clearInterval(intervalId)
} else if (++count >= 20) {
console.log(`No element present on DOM with divId '${divId}'.`)
logger.log(`No element present on DOM with divId '${divId}'.`)
clearInterval(intervalId)
}
}, 500)
Expand All @@ -99,26 +100,30 @@ export const handleJson = (targetingMsgJson) => {
document.dispatchEvent(jsonEvent)
}

function handleCustomHtmlPreviewPostMessageEvent (event, logger) {
const eventData = JSON.parse(event.data)
const inAppNotifs = eventData.inapp_notifs
const msgContent = inAppNotifs[0].msgContent
if (eventData && msgContent && msgContent.templateType === 'custom-html' && msgContent.type === 5) {
renderCustomHtml(inAppNotifs[0], logger)
}
}

export const checkCustomHtmlNativeDisplayPreview = (logger) => {
const searchParams = new URLSearchParams(window.location.search)
const ctType = searchParams.get('ctActionMode')
if (ctType) {
const parentWindow = window.opener
switch (ctType) {
case 'ctCustomHtmlPreview':
case CUSTOM_HTML_PREVIEW:
if (parentWindow) {
parentWindow.postMessage('ready', '*')
window.addEventListener('message', (event) => {
const eventData = JSON.parse(event.data)
const inAppNotifs = eventData.inapp_notifs
const msgContent = inAppNotifs[0].msgContent
if (eventData && msgContent.templateType === 'custom-html' && msgContent.type === 5) {
renderCustomHtml(inAppNotifs[0])
}
}, false)
const eventHandler = (event) => handleCustomHtmlPreviewPostMessageEvent(event, logger)
window.addEventListener('message', eventHandler, false)
}
break
default:
logger.debug(`unknown unknown query param ${ctType}`)
break
}
}
Expand Down
1 change: 1 addition & 0 deletions src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const TIMER_FOR_NOTIF_BADGE_UPDATE = 300
export const OLD_SOFT_PROMPT_SELCTOR_ID = 'wzrk_wrapper'
export const NEW_SOFT_PROMPT_SELCTOR_ID = 'pnWrapper'
export const POPUP_LOADING = 'WZRK_POPUP_LOADING'
export const CUSTOM_HTML_PREVIEW = 'ctCustomHtmlPreview'

export const SYSTEM_EVENTS = [
'Stayed',
Expand Down

0 comments on commit 98ab394

Please sign in to comment.