@product7/product7-js 0.6.8 → 0.6.9

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.
@@ -1458,6 +1458,24 @@
1458
1458
  }
1459
1459
  }
1460
1460
 
1461
+ let _cached = null;
1462
+
1463
+ async function getIpInfo() {
1464
+ if (_cached) return _cached;
1465
+
1466
+ try {
1467
+ const res = await fetch('http://ip-api.com/json');
1468
+ if (!res.ok) return null;
1469
+ const data = await res.json();
1470
+ if (data.status === 'success') {
1471
+ _cached = data;
1472
+ }
1473
+ return _cached;
1474
+ } catch {
1475
+ return null;
1476
+ }
1477
+ }
1478
+
1461
1479
  class APIService extends BaseAPIService {
1462
1480
  constructor(config = {}) {
1463
1481
  super(config);
@@ -1561,6 +1579,9 @@
1561
1579
  if (metadata.attributes) payload.attributes = metadata.attributes;
1562
1580
  if (metadata.company) payload.company = metadata.company;
1563
1581
 
1582
+ const ipInfo = await getIpInfo();
1583
+ if (ipInfo) payload.ip_info = ipInfo;
1584
+
1564
1585
  const response = await this._makeRequest('/widget/identify', {
1565
1586
  method: 'POST',
1566
1587
  headers: {