|
101 | 101 | } |
102 | 102 | }; |
103 | 103 |
|
104 | | - // Helper function to get schema URL |
105 | | - const getSchemaUrl = (eventType, environment) => { |
106 | | - const schema = SCHEMA_CONFIG[environment][eventType]; |
107 | | - return `iglu:${schema.name}/jsonschema/${schema.version}`; |
108 | | - }; |
109 | | - |
110 | 104 | const getEnvironment = () => { |
111 | 105 | const apiUrl = WIDGET_SETTINGS.apiUrl; |
112 | 106 | if (apiUrl.startsWith("https://projectaanvraag-api.uitdatabank.dev")) |
113 | 107 | return { |
114 | 108 | name: "dev", |
115 | | - collector: "sneeuwploeg-dev.uitdatabank.be" |
| 109 | + collector: "sneeuwploeg-dev.uitdatabank.be", |
| 110 | + snowplowBackendEnvironment: "dev" // Maps to dev Snowplow backend |
| 111 | + }; |
| 112 | + if (apiUrl.startsWith("https://projectaanvraag-api-test.uitdatabank.be")) |
| 113 | + return { |
| 114 | + name: "test", |
| 115 | + collector: "sneeuwploeg-dev.uitdatabank.be", // Use dev collector |
| 116 | + snowplowBackendEnvironment: "dev" // Test frontend maps to dev Snowplow backend |
116 | 117 | }; |
117 | 118 | if (apiUrl.startsWith("https://projectaanvraag-api.uitdatabank.be")) |
118 | 119 | return { |
119 | 120 | name: "prod", |
120 | 121 | collectors: [ |
121 | | - "sneeuwploeg.uitdatabank.be", // old collector |
| 122 | + "sneeuwploeg.uitdatabank.be", // old collector |
122 | 123 | "sneeuwploeg-prd.uitdatabank.be" // new collector |
123 | | - ] |
| 124 | + ], |
| 125 | + snowplowBackendEnvironment: "prod" // Maps to prod Snowplow backend |
124 | 126 | }; |
125 | 127 | }; |
126 | 128 |
|
127 | 129 | const environmentConfig = getEnvironment(); |
128 | 130 | const environment = environmentConfig.name; |
| 131 | + const snowplowBackendEnvironment = environmentConfig.snowplowBackendEnvironment; |
129 | 132 |
|
130 | 133 | const getTimeSpentInSeconds = () => { |
131 | 134 | const endTime = new Date(); |
|
154 | 157 |
|
155 | 158 | initializeSnowPlow(window, document, "script", SNOWPLOW_JS_URL, "widgetSnowplow"); |
156 | 159 |
|
157 | | - // Initialize trackers based on environment |
158 | | - if (environment === "dev") { |
159 | | - window.widgetSnowplow( |
160 | | - "newTracker", |
161 | | - "widgets-tracker-dev", |
162 | | - environmentConfig.collector, |
163 | | - { |
164 | | - appId: "widgets", |
165 | | - platform: "web", |
166 | | - cookieDomain: null, |
167 | | - cookieName: "sppubliq", |
168 | | - sessionCookieTimeout: 3600, |
169 | | - discoverRootDomain: true, |
170 | | - eventMethod: "post", |
171 | | - encodeBase64: true, |
172 | | - respectDoNotTrack: false, |
173 | | - userFingerprint: true, |
174 | | - postPath: "/publiq/t", |
175 | | - contexts: { |
176 | | - webPage: true, |
177 | | - performanceTiming: false, |
178 | | - gaCookies: true, |
179 | | - geolocation: false, |
180 | | - }, |
181 | | - } |
182 | | - ); |
183 | | - } else { |
184 | | - // Production environment - dual tracking |
185 | | - environmentConfig.collectors.forEach((collector, index) => { |
| 160 | + // Common tracker configuration |
| 161 | + const getTrackerConfig = () => ({ |
| 162 | + appId: "widgets", |
| 163 | + platform: "web", |
| 164 | + cookieDomain: null, |
| 165 | + cookieName: "sppubliq", // Same cookie name for all trackers |
| 166 | + sessionCookieTimeout: 3600, |
| 167 | + discoverRootDomain: true, |
| 168 | + eventMethod: "post", |
| 169 | + encodeBase64: true, |
| 170 | + respectDoNotTrack: false, |
| 171 | + userFingerprint: true, |
| 172 | + postPath: "/publiq/t", |
| 173 | + contexts: { |
| 174 | + webPage: true, |
| 175 | + performanceTiming: false, |
| 176 | + gaCookies: true, |
| 177 | + geolocation: false, |
| 178 | + } |
| 179 | + }); |
| 180 | + |
| 181 | + // Initialize tracker(s) based on environment |
| 182 | + const initializeTrackers = () => { |
| 183 | + if (environment === "prod") { |
| 184 | + // Production environment - dual tracking with identical configuration |
| 185 | + environmentConfig.collectors.forEach((collector, index) => { |
| 186 | + window.widgetSnowplow( |
| 187 | + "newTracker", |
| 188 | + `widgets-tracker-${index}`, |
| 189 | + collector, |
| 190 | + getTrackerConfig() |
| 191 | + ); |
| 192 | + }); |
| 193 | + } else { |
| 194 | + // Dev/Test environments - single tracker |
186 | 195 | window.widgetSnowplow( |
187 | 196 | "newTracker", |
188 | | - `widgets-tracker-${index}`, |
189 | | - collector, |
190 | | - { |
191 | | - appId: "widgets", |
192 | | - platform: "web", |
193 | | - cookieDomain: null, |
194 | | - cookieName: `sppubliq`, |
195 | | - sessionCookieTimeout: 3600, |
196 | | - discoverRootDomain: true, |
197 | | - eventMethod: "post", |
198 | | - encodeBase64: true, |
199 | | - respectDoNotTrack: false, |
200 | | - userFingerprint: true, |
201 | | - postPath: "/publiq/t", |
202 | | - contexts: { |
203 | | - webPage: true, |
204 | | - performanceTiming: false, |
205 | | - gaCookies: true, |
206 | | - geolocation: false, |
207 | | - }, |
208 | | - } |
| 197 | + `widgets-tracker-${environment}`, // Use specific environment name in tracker |
| 198 | + environmentConfig.collector, |
| 199 | + getTrackerConfig() |
209 | 200 | ); |
210 | | - }); |
211 | | - } |
| 201 | + } |
| 202 | + }; |
| 203 | + |
| 204 | + initializeTrackers(); |
212 | 205 |
|
213 | 206 | // Event data collectors by environment |
214 | 207 | // These functions gather all required data for each event type in each environment |
|
258 | 251 | environment, |
259 | 252 | }) |
260 | 253 | }, |
| 254 | + test: { |
| 255 | + // Test environment uses same collectors as dev |
| 256 | + ...EVENT_DATA_COLLECTORS.dev |
| 257 | + }, |
261 | 258 | prod: { |
262 | 259 | page_unload: () => { |
263 | 260 | const timeSpent = getTimeSpentInSeconds(); |
|
349 | 346 | } |
350 | 347 | }) |
351 | 348 | }, |
| 349 | + test: { |
| 350 | + // Test environment uses same builders as dev |
| 351 | + ...EVENT_BUILDERS.dev |
| 352 | + }, |
352 | 353 | prod: { |
353 | 354 | page_unload: (data) => ({ |
354 | 355 | schema: getSchemaUrl('page_unload', 'prod'), |
|
500 | 501 | trackerNames |
501 | 502 | ); |
502 | 503 | }); |
| 504 | + |
| 505 | + const getSchemaUrl = (eventType) => { |
| 506 | + const schema = SCHEMA_CONFIG[snowplowBackendEnvironment][eventType]; |
| 507 | + return `iglu:${schema.name}/jsonschema/${schema.version}`; |
| 508 | + }; |
503 | 509 | }; |
504 | 510 | })(CultuurnetWidgets); |
0 commit comments