@penguin-wolf/braze-integration 2.1.0 → 2.1.1

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.
@@ -6,7 +6,7 @@ if(!window.BrazeIntegration) {
6
6
  class BrazeIntegration {
7
7
  static instance;
8
8
  static version = packageJson.version;
9
-
9
+
10
10
  constructor(sdkKey, sdkUrl, enableLogging=false) {
11
11
  if(!sdkKey || !sdkUrl) {
12
12
  console.error('SDK Key and SDK URL are required to construct BrazeIntegration');
@@ -17,27 +17,27 @@ if(!window.BrazeIntegration) {
17
17
  // check if sdkKey and sdkUrl match the existing instance
18
18
  if(BrazeIntegration.instance.sdkKey != sdkKey && BrazeIntegration.instance.sdkUrl != sdkUrl) {
19
19
  throw new Error('BrazeIntegration already initialized with different SDK Key or SDK URL');
20
- }
20
+ }
21
21
  return BrazeIntegration.instance;
22
22
  }
23
-
23
+
24
24
  this.sdkKey = sdkKey;
25
25
  this.sdkUrl = sdkUrl;
26
- this.enableLogging = enableLogging;
26
+ this.enableLogging = enableLogging;
27
27
  this.braze = braze;
28
28
 
29
29
  if(this.enableLogging) {
30
30
  window.braze = braze;
31
31
  }
32
-
32
+
33
33
  BrazeIntegration.instance = this;
34
34
 
35
35
  this.initialize();
36
36
  }
37
-
37
+
38
38
  initialize() {
39
39
  if(this._initialized) return;
40
-
40
+
41
41
  braze.initialize(this.sdkKey, {
42
42
  baseUrl: this.sdkUrl,
43
43
  enableLogging: this.enableLogging,
@@ -46,9 +46,11 @@ if(!window.BrazeIntegration) {
46
46
  });
47
47
 
48
48
  this.changeUserFromUrlParameter();
49
-
49
+
50
50
  braze.openSession();
51
-
51
+
52
+ this.setupBannerImpressionLogging();
53
+
52
54
  this._initialized = true;
53
55
  }
54
56
 
@@ -69,6 +71,53 @@ if(!window.BrazeIntegration) {
69
71
  return false;
70
72
  }
71
73
 
74
+ /*
75
+ * Banner impression logging
76
+ *
77
+ * The Braze SDK is silent on successful banner impressions — it only logs when
78
+ * dedup suppresses one ("Not logging banners impression for ID X..."). This
79
+ * watches the SDK's own impression-marker attributes (set inside
80
+ * detectBannerImpressions) and emits a log the moment a banner is actually
81
+ * marked as impressed, with a clear FULLY IMPRESSED indicator when both top
82
+ * and bottom markers have been set (which is the moment logBannerImpressions
83
+ * is called internally).
84
+ *
85
+ * Gated on enableLogging so it only runs in dev/debug environments.
86
+ */
87
+ setupBannerImpressionLogging() {
88
+ if(!this.enableLogging) return;
89
+
90
+ const TOP_ATTR = 'data-ab-had-top-impression';
91
+ const BOTTOM_ATTR = 'data-ab-had-bottom-impression';
92
+ const PLACEMENT_ID_ATTR = 'data-ab-banner-placement-id';
93
+
94
+ const observer = new MutationObserver(mutations => {
95
+ for(const m of mutations) {
96
+ if(m.type !== 'attributes') continue;
97
+ const attr = m.attributeName;
98
+ if(attr !== TOP_ATTR && attr !== BOTTOM_ATTR) continue;
99
+
100
+ const el = m.target;
101
+ const placementId = el.getAttribute(PLACEMENT_ID_ATTR) || '(none)';
102
+ const edge = attr === TOP_ATTR ? 'TOP' : 'BOTTOM';
103
+ const topNow = el.getAttribute(TOP_ATTR) === 'true';
104
+ const bottomNow = el.getAttribute(BOTTOM_ATTR) === 'true';
105
+ const fullyImpressed = topNow && bottomNow;
106
+
107
+ console.log(
108
+ `%cBraze: banner impression marker — ${placementId} ${edge}${fullyImpressed ? ' ⇒ FULLY IMPRESSED' : ''}`,
109
+ `color:${fullyImpressed ? '#2ECC71' : '#F39C12'};font-weight:bold`,
110
+ );
111
+ }
112
+ });
113
+
114
+ observer.observe(document.documentElement, {
115
+ attributes: true,
116
+ attributeFilter: [TOP_ATTR, BOTTOM_ATTR],
117
+ subtree: true,
118
+ });
119
+ }
120
+
72
121
  log() {
73
122
  if(!this.enableLogging) return;
74
123
  console.log(...arguments);
@@ -77,11 +126,11 @@ if(!window.BrazeIntegration) {
77
126
  }
78
127
 
79
128
  window.BrazeIntegration = BrazeIntegration;
80
- }
129
+ }
81
130
  else {
82
131
  if(window.BrazeIntegration.version !== packageJson.version) {
83
132
  console.warn('Warning: BrazeIntegration version mismatch. BrazeIntegration has been loaded in multiple different versions which may cause issues, ensure every plugin is using the same version to avoid issues');
84
133
  }
85
- }
134
+ }
86
135
 
87
- export default window.BrazeIntegration;
136
+ export default window.BrazeIntegration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penguin-wolf/braze-integration",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "main": "braze-integration.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"