@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.
package/package.json
CHANGED
package/src/core/APIService.js
CHANGED
|
@@ -4,6 +4,7 @@ import { HelpService } from '../api/services/HelpService.js';
|
|
|
4
4
|
import { LiveChatService } from '../api/services/LiveChatService.js';
|
|
5
5
|
import { SurveyService } from '../api/services/SurveyService.js';
|
|
6
6
|
import { BaseAPIService } from './BaseAPIService.js';
|
|
7
|
+
import { getIpInfo } from '../utils/getIpInfo.js';
|
|
7
8
|
|
|
8
9
|
export class APIService extends BaseAPIService {
|
|
9
10
|
constructor(config = {}) {
|
|
@@ -108,6 +109,9 @@ export class APIService extends BaseAPIService {
|
|
|
108
109
|
if (metadata.attributes) payload.attributes = metadata.attributes;
|
|
109
110
|
if (metadata.company) payload.company = metadata.company;
|
|
110
111
|
|
|
112
|
+
const ipInfo = await getIpInfo();
|
|
113
|
+
if (ipInfo) payload.ip_info = ipInfo;
|
|
114
|
+
|
|
111
115
|
const response = await this._makeRequest('/widget/identify', {
|
|
112
116
|
method: 'POST',
|
|
113
117
|
headers: {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
let _cached = null;
|
|
2
|
+
|
|
3
|
+
export async function getIpInfo() {
|
|
4
|
+
if (_cached) return _cached;
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const res = await fetch('http://ip-api.com/json');
|
|
8
|
+
if (!res.ok) return null;
|
|
9
|
+
const data = await res.json();
|
|
10
|
+
if (data.status === 'success') {
|
|
11
|
+
_cached = data;
|
|
12
|
+
}
|
|
13
|
+
return _cached;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|