|
| 1 | +import { omit } from 'ramda'; |
1 | 2 | import { describe, expect, it } from 'vitest'; |
2 | 3 | import { MixpanelProvider } from './mixpanel'; |
3 | 4 |
|
@@ -120,7 +121,7 @@ describe('mixpanel', () => { |
120 | 121 | referrer_name: 'Google', |
121 | 122 | referrer_type: 'search', |
122 | 123 | imported_at: expect.any(String), |
123 | | - sdk_name: 'mixpanel', |
| 124 | + sdk_name: 'mixpanel (web)', |
124 | 125 | sdk_version: '1.0.0', |
125 | 126 | }); |
126 | 127 | }); |
@@ -175,4 +176,144 @@ describe('mixpanel', () => { |
175 | 176 | 'nested.level1.level2': 'value', |
176 | 177 | }); |
177 | 178 | }); |
| 179 | + |
| 180 | + it('should handle react-native referrer', async () => { |
| 181 | + const provider = new MixpanelProvider('pid', { |
| 182 | + from: '2025-01-01', |
| 183 | + to: '2025-01-02', |
| 184 | + serviceAccount: 'sa', |
| 185 | + serviceSecret: 'ss', |
| 186 | + projectId: '123', |
| 187 | + provider: 'mixpanel', |
| 188 | + type: 'api', |
| 189 | + mapScreenViewProperty: undefined, |
| 190 | + }); |
| 191 | + |
| 192 | + const rawEvent = { |
| 193 | + event: 'ec_search_error', |
| 194 | + properties: { |
| 195 | + time: 1759947367, |
| 196 | + distinct_id: '3385916', |
| 197 | + $browser: 'Mobile Safari', |
| 198 | + $browser_version: null, |
| 199 | + $city: 'Bengaluru', |
| 200 | + $current_url: |
| 201 | + 'https://web.landeed.com/karnataka/ec-encumbrance-certificate', |
| 202 | + $device: 'iPhone', |
| 203 | + $device_id: |
| 204 | + '199b498af1036c-0e943279a1292e-5c0f4368-51bf4-199b498af1036c', |
| 205 | + $initial_referrer: 'https://www.google.com/', |
| 206 | + $initial_referring_domain: 'www.google.com', |
| 207 | + $insert_id: 'bclkaepeqcfuzt4v', |
| 208 | + $lib_version: '2.60.0', |
| 209 | + $mp_api_endpoint: 'api-js.mixpanel.com', |
| 210 | + $mp_api_timestamp_ms: 1759927570699, |
| 211 | + $os: 'iOS', |
| 212 | + $region: 'Karnataka', |
| 213 | + $screen_height: 852, |
| 214 | + $screen_width: 393, |
| 215 | + $search_engine: 'google', |
| 216 | + $user_id: '3385916', |
| 217 | + binaryReadableVersion: 'NA', |
| 218 | + binaryVersion: 'NA', |
| 219 | + component: '/karnataka/ec-encumbrance-certificate', |
| 220 | + errMsg: 'Request failed with status code 500', |
| 221 | + errType: 'SERVER_ERROR', |
| 222 | + isSilentSearch: false, |
| 223 | + isTimeout: false, |
| 224 | + jsVersion: '0.42.0', |
| 225 | + language: 'english', |
| 226 | + mp_country_code: 'IN', |
| 227 | + mp_lib: 'web', |
| 228 | + mp_processing_time_ms: 1759927592421, |
| 229 | + mp_sent_by_lib_version: '2.60.0', |
| 230 | + os: 'web', |
| 231 | + osVersion: |
| 232 | + 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/388.0.811331708 Mobile/15E148 Safari/604.1', |
| 233 | + phoneBrand: 'NA', |
| 234 | + phoneManufacturer: 'NA', |
| 235 | + phoneModel: 'NA', |
| 236 | + searchUuid: '68e65d08-fd81-4ded-37d3-2b08d2bc70c3', |
| 237 | + serverVersion: 'web2.0', |
| 238 | + state: 17, |
| 239 | + stateStr: '17', |
| 240 | + statusCode: 500, |
| 241 | + type: 'result_event', |
| 242 | + utm_medium: 'cpc', |
| 243 | + utm_source: |
| 244 | + 'google%26utm_medium=cpc%26utm_campaignid=21380769590%26utm_adgroupid=%26utm_adid=%26utm_term=%26utm_device=m%26utm_network=%26utm_location=9062055%26gclid=%26gad_campaignid=21374496705%26gbraid=0AAAAAoV7mTM9mWFripzQ2Od0xXAfrW6p3%26wbraid=CmAKCQjwi4PHBhCUA', |
| 245 | + }, |
| 246 | + }; |
| 247 | + |
| 248 | + const res = provider.transformEvent(rawEvent); |
| 249 | + |
| 250 | + expect(res.id.length).toBeGreaterThan(30); |
| 251 | + expect(res.imported_at).toMatch( |
| 252 | + /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/, |
| 253 | + ); |
| 254 | + expect(omit(['id', 'imported_at'], res)).toEqual({ |
| 255 | + brand: 'Apple', |
| 256 | + browser: 'GSA', |
| 257 | + browser_version: 'null', |
| 258 | + city: 'Bengaluru', |
| 259 | + country: 'IN', |
| 260 | + created_at: '2025-10-08T18:16:07.000Z', |
| 261 | + device: 'mobile', |
| 262 | + device_id: '199b498af1036c-0e943279a1292e-5c0f4368-51bf4-199b498af1036c', |
| 263 | + duration: 0, |
| 264 | + latitude: null, |
| 265 | + longitude: null, |
| 266 | + model: 'iPhone', |
| 267 | + name: 'ec_search_error', |
| 268 | + origin: 'https://web.landeed.com', |
| 269 | + os: 'iOS', |
| 270 | + os_version: '18.7.0', |
| 271 | + path: '/karnataka/ec-encumbrance-certificate', |
| 272 | + profile_id: '3385916', |
| 273 | + project_id: 'pid', |
| 274 | + properties: { |
| 275 | + __lib_version: '2.60.0', |
| 276 | + '__query.gad_campaignid': '21374496705', |
| 277 | + '__query.gbraid': '0AAAAAoV7mTM9mWFripzQ2Od0xXAfrW6p3', |
| 278 | + '__query.utm_campaignid': '21380769590', |
| 279 | + '__query.utm_device': 'm', |
| 280 | + '__query.utm_location': '9062055', |
| 281 | + '__query.utm_medium': 'cpc', |
| 282 | + '__query.utm_source': 'google', |
| 283 | + '__query.wbraid': 'CmAKCQjwi4PHBhCUA', |
| 284 | + __screen: '393x852', |
| 285 | + __source_insert_id: 'bclkaepeqcfuzt4v', |
| 286 | + __userAgent: |
| 287 | + 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/388.0.811331708 Mobile/15E148 Safari/604.1', |
| 288 | + binaryReadableVersion: 'NA', |
| 289 | + binaryVersion: 'NA', |
| 290 | + component: '/karnataka/ec-encumbrance-certificate', |
| 291 | + errMsg: 'Request failed with status code 500', |
| 292 | + errType: 'SERVER_ERROR', |
| 293 | + isSilentSearch: 'false', |
| 294 | + isTimeout: 'false', |
| 295 | + jsVersion: '0.42.0', |
| 296 | + language: 'english', |
| 297 | + os: 'web', |
| 298 | + osVersion: |
| 299 | + 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/388.0.811331708 Mobile/15E148 Safari/604.1', |
| 300 | + phoneBrand: 'NA', |
| 301 | + phoneManufacturer: 'NA', |
| 302 | + phoneModel: 'NA', |
| 303 | + searchUuid: '68e65d08-fd81-4ded-37d3-2b08d2bc70c3', |
| 304 | + serverVersion: 'web2.0', |
| 305 | + state: '17', |
| 306 | + stateStr: '17', |
| 307 | + statusCode: '500', |
| 308 | + type: 'result_event', |
| 309 | + }, |
| 310 | + referrer: 'https://www.google.com', |
| 311 | + referrer_name: 'Google', |
| 312 | + referrer_type: 'search', |
| 313 | + region: 'Karnataka', |
| 314 | + sdk_name: 'mixpanel (web)', |
| 315 | + sdk_version: '1.0.0', |
| 316 | + session_id: '', |
| 317 | + }); |
| 318 | + }); |
178 | 319 | }); |
0 commit comments