@ordersune/crm-web-sdk 1.0.9 → 1.0.10
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.
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +1 -0
- package/dist/web-sdk.d.ts +4 -1
- package/dist/web-sdk.js +48 -3
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -81,4 +81,13 @@ export interface ShowInAppMessageOptions {
|
|
|
81
81
|
headerColor: string;
|
|
82
82
|
messageColor: string;
|
|
83
83
|
closeColor: string;
|
|
84
|
+
campaignId: string;
|
|
85
|
+
}
|
|
86
|
+
export interface CampaignPayload {
|
|
87
|
+
campaignId: string;
|
|
88
|
+
opened: boolean;
|
|
89
|
+
clicked: boolean;
|
|
90
|
+
deviceId: string;
|
|
91
|
+
timestamp: number;
|
|
92
|
+
dismissed?: boolean;
|
|
84
93
|
}
|
package/dist/types/index.js
CHANGED
package/dist/web-sdk.d.ts
CHANGED
|
@@ -42,8 +42,11 @@ export declare class WebSDK {
|
|
|
42
42
|
private queueEvent;
|
|
43
43
|
private processBatch;
|
|
44
44
|
private sendBatchToServer;
|
|
45
|
-
displayInAppMessage(inAppMessageData: string, context?: any): void;
|
|
45
|
+
displayInAppMessage(inAppMessageData: string, campaignId: string, context?: any): void;
|
|
46
46
|
private hexToColor;
|
|
47
47
|
private openWebUrl;
|
|
48
48
|
private showInAppMessage;
|
|
49
|
+
private logInAppMessageClick;
|
|
50
|
+
private processCampaignClick;
|
|
51
|
+
private buildCampaignPayload;
|
|
49
52
|
}
|
package/dist/web-sdk.js
CHANGED
|
@@ -398,7 +398,7 @@ class WebSDK {
|
|
|
398
398
|
throw error;
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
|
-
displayInAppMessage(inAppMessageData, context) {
|
|
401
|
+
displayInAppMessage(inAppMessageData, campaignId, context) {
|
|
402
402
|
const transformedData = JSON.parse(inAppMessageData);
|
|
403
403
|
const title = transformedData.header;
|
|
404
404
|
const body = transformedData.message;
|
|
@@ -420,7 +420,8 @@ class WebSDK {
|
|
|
420
420
|
dismissMessageInSeconds: transformedData.modal.dismissMessageInSeconds,
|
|
421
421
|
headerColor: transformedData.modal.headerColor,
|
|
422
422
|
messageColor: transformedData.modal.messageColor,
|
|
423
|
-
closeColor: transformedData.modal.closeColor
|
|
423
|
+
closeColor: transformedData.modal.closeColor,
|
|
424
|
+
campaignId: campaignId,
|
|
424
425
|
});
|
|
425
426
|
}
|
|
426
427
|
hexToColor(hexColor) {
|
|
@@ -436,7 +437,7 @@ class WebSDK {
|
|
|
436
437
|
}
|
|
437
438
|
}
|
|
438
439
|
showInAppMessage(options) {
|
|
439
|
-
const { title, body, primaryButtonText, secondaryButtonText, imageUrl, onClose, buttonPropertiesPrimary, buttonPropertiesSecondary, dismissMessageAutomatically, dismissMessageInSeconds, headerColor, messageColor, closeColor } = options;
|
|
440
|
+
const { title, body, primaryButtonText, secondaryButtonText, imageUrl, onClose, buttonPropertiesPrimary, buttonPropertiesSecondary, dismissMessageAutomatically, dismissMessageInSeconds, headerColor, messageColor, closeColor, campaignId, } = options;
|
|
440
441
|
// Create modal container
|
|
441
442
|
const modalOverlay = document.createElement('div');
|
|
442
443
|
modalOverlay.style.position = 'fixed';
|
|
@@ -473,6 +474,7 @@ class WebSDK {
|
|
|
473
474
|
if (onClose) {
|
|
474
475
|
onClose();
|
|
475
476
|
}
|
|
477
|
+
this.logInAppMessageClick(campaignId, false, true, true);
|
|
476
478
|
document.body.removeChild(modalOverlay);
|
|
477
479
|
};
|
|
478
480
|
// Create content
|
|
@@ -563,6 +565,7 @@ class WebSDK {
|
|
|
563
565
|
secondaryButton.style.cursor = 'pointer';
|
|
564
566
|
secondaryButton.onclick = () => {
|
|
565
567
|
document.body.removeChild(modalOverlay);
|
|
568
|
+
this.logInAppMessageClick(campaignId, true, true, false);
|
|
566
569
|
onSecondaryButtonPress();
|
|
567
570
|
};
|
|
568
571
|
buttonsContainer.appendChild(secondaryButton);
|
|
@@ -583,6 +586,7 @@ class WebSDK {
|
|
|
583
586
|
primaryButton.style.cursor = 'pointer';
|
|
584
587
|
primaryButton.onclick = () => {
|
|
585
588
|
document.body.removeChild(modalOverlay);
|
|
589
|
+
this.logInAppMessageClick(campaignId, true, true, false);
|
|
586
590
|
onPrimaryButtonPress();
|
|
587
591
|
};
|
|
588
592
|
buttonsContainer.appendChild(primaryButton);
|
|
@@ -610,5 +614,46 @@ class WebSDK {
|
|
|
610
614
|
}
|
|
611
615
|
});
|
|
612
616
|
}
|
|
617
|
+
async logInAppMessageClick(campaignId, clicked, opened, dismissed) {
|
|
618
|
+
const campaignClickPayload = await this.buildCampaignPayload(campaignId, opened, clicked, dismissed);
|
|
619
|
+
await this.processCampaignClick(campaignClickPayload);
|
|
620
|
+
}
|
|
621
|
+
async processCampaignClick(payload) {
|
|
622
|
+
try {
|
|
623
|
+
const response = await fetch(`${this.endpoint}/analytics/clicks`, {
|
|
624
|
+
method: "POST",
|
|
625
|
+
headers: {
|
|
626
|
+
"Content-Type": "application/json",
|
|
627
|
+
"x-api-key": this.apiKey,
|
|
628
|
+
},
|
|
629
|
+
body: JSON.stringify(payload),
|
|
630
|
+
});
|
|
631
|
+
if (!response.ok) {
|
|
632
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
633
|
+
}
|
|
634
|
+
if (this.debug) {
|
|
635
|
+
(0, utils_1.log)(this.debug, `process campaign click dispatched successfully: ${payload.campaignId}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
catch (error) {
|
|
639
|
+
(0, utils_1.log)(this.debug, "Error processing campaign click:", error);
|
|
640
|
+
throw error;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async buildCampaignPayload(campaignId, opened, clicked, dismissed) {
|
|
644
|
+
const timestamp = Date.now();
|
|
645
|
+
const deviceId = this.deviceId;
|
|
646
|
+
const payload = {
|
|
647
|
+
campaignId,
|
|
648
|
+
opened,
|
|
649
|
+
clicked,
|
|
650
|
+
deviceId,
|
|
651
|
+
timestamp,
|
|
652
|
+
};
|
|
653
|
+
if (dismissed !== undefined) {
|
|
654
|
+
payload.dismissed = dismissed;
|
|
655
|
+
}
|
|
656
|
+
return payload;
|
|
657
|
+
}
|
|
613
658
|
}
|
|
614
659
|
exports.WebSDK = WebSDK;
|