@penguin-wolf/braze-integration 2.1.1 → 2.1.2
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/braze-integration.js +27 -0
- package/package.json +1 -1
package/braze-integration.js
CHANGED
|
@@ -49,11 +49,38 @@ if(!window.BrazeIntegration) {
|
|
|
49
49
|
|
|
50
50
|
braze.openSession();
|
|
51
51
|
|
|
52
|
+
this.applyBannerImpressionFix();
|
|
52
53
|
this.setupBannerImpressionLogging();
|
|
53
54
|
|
|
54
55
|
this._initialized = true;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
/*
|
|
59
|
+
* Fix for Braze SDK bug: freshly-inserted banner iframes return a {0,0,0,0}
|
|
60
|
+
* bounding rect before the browser has computed layout, which trivially
|
|
61
|
+
* satisfies the SDK's viewport check and causes an impression to be logged
|
|
62
|
+
* for every banner on first insert — regardless of actual visibility.
|
|
63
|
+
*
|
|
64
|
+
* We patch Element.prototype.getBoundingClientRect to detect this pathological
|
|
65
|
+
* case for banner elements specifically and substitute an off-screen rect.
|
|
66
|
+
* The SDK's later scroll-triggered checks see the real rects and log accurately.
|
|
67
|
+
*
|
|
68
|
+
* Always runs (not gated on enableLogging) — this is a bug workaround, not debug.
|
|
69
|
+
*/
|
|
70
|
+
applyBannerImpressionFix() {
|
|
71
|
+
const original = Element.prototype.getBoundingClientRect;
|
|
72
|
+
Element.prototype.getBoundingClientRect = function() {
|
|
73
|
+
const rect = original.call(this);
|
|
74
|
+
if(
|
|
75
|
+
(this.classList?.contains('ab-html-banner') || this.classList?.contains('ab-html-control-banner'))
|
|
76
|
+
&& rect.top === 0 && rect.bottom === 0 && rect.width === 0 && rect.height === 0
|
|
77
|
+
) {
|
|
78
|
+
return new DOMRect(0, -99999, 0, 0);
|
|
79
|
+
}
|
|
80
|
+
return rect;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
57
84
|
changeUserFromUrlParameter() {
|
|
58
85
|
const urlParams = new URLSearchParams(window.location.search);
|
|
59
86
|
if(urlParams.has('external_id')) {
|