@pack/packlytics 1.0.1-ab-test.1 → 1.0.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.
package/dist/packlytics.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function sendEvent(request: Request, session: any, params: {
|
|
2
2
|
storefrontId: string;
|
|
3
3
|
sessionSecret: string;
|
|
4
4
|
}): Promise<Response | undefined>;
|
|
5
|
+
export declare function packlytics(pack: any, request: Request, next: () => Promise<Response>): Promise<Response>;
|
|
5
6
|
//# sourceMappingURL=packlytics.d.ts.map
|
package/dist/packlytics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packlytics.d.ts","sourceRoot":"","sources":["../src/packlytics.ts"],"names":[],"mappings":"AAOA,wBAAsB,
|
|
1
|
+
{"version":3,"file":"packlytics.d.ts","sourceRoot":"","sources":["../src/packlytics.ts"],"names":[],"mappings":"AAOA,wBAAsB,SAAS,CAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE;IACN,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB,iCA2CF;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,GAAG,EACT,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAenB"}
|
package/dist/packlytics.js
CHANGED
|
@@ -4,7 +4,7 @@ import { trackPageHit } from "./utils/page-hit";
|
|
|
4
4
|
import { getDevice } from "./utils/get-client-device";
|
|
5
5
|
import { getStorefrontHeaders } from "@shopify/remix-oxygen";
|
|
6
6
|
import { getClientLocation } from "./utils/get-client-location";
|
|
7
|
-
export async function
|
|
7
|
+
export async function sendEvent(request, session, params) {
|
|
8
8
|
if (process.env.NODE_ENV === "development") {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
@@ -12,32 +12,43 @@ export async function packlytics(request, session, params) {
|
|
|
12
12
|
if (!!session.get("previewEnabled")) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
+
const payload = await request.json();
|
|
15
16
|
const url = new URL(request.url);
|
|
16
17
|
const ipaddress = getStorefrontHeaders(request)["buyerIp"] || "";
|
|
17
18
|
const dataToHash = `${request.headers.get("user-agent")}${ipaddress}${url.hostname}`;
|
|
18
19
|
const packlyticsId = getPacklyticsId(dataToHash, params.sessionSecret);
|
|
19
|
-
const testSession = session.get("test");
|
|
20
20
|
const locale = getClientLocales(request) || ["en-US"];
|
|
21
|
-
const location = getClientLocation(locale[0]);
|
|
21
|
+
const location = getClientLocation(payload.locale || locale[0]);
|
|
22
22
|
return trackPageHit(params.storefrontId, packlyticsId)({
|
|
23
23
|
"pack-session-id": session.id, // This session ID is saved on the __pack cookie
|
|
24
|
-
"user-agent": request.headers.get("user-agent") || "",
|
|
25
|
-
pathname:
|
|
26
|
-
query:
|
|
27
|
-
|
|
28
|
-
referrer:
|
|
24
|
+
"user-agent": payload.userAgent || request.headers.get("user-agent") || "",
|
|
25
|
+
pathname: payload.pathname,
|
|
26
|
+
query: payload.query,
|
|
27
|
+
screen: payload.screen,
|
|
28
|
+
referrer: payload.referrer,
|
|
29
|
+
hostname: payload.hostname,
|
|
29
30
|
ipaddress: ipaddress,
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
userTimeZone: payload.userTimeZone,
|
|
32
|
+
language: payload.language || getClientLocales(request) || "",
|
|
33
|
+
locale: payload.locale || locale[0],
|
|
32
34
|
location: location,
|
|
33
|
-
connection: request.headers.get("connection") || "",
|
|
34
|
-
|
|
35
|
+
connection: payload.connection || request.headers.get("connection") || "",
|
|
36
|
+
deviceCategory: payload.deviceCategory || "",
|
|
37
|
+
href: payload.href || request.url,
|
|
35
38
|
...getDevice(request.headers.get("user-agent") || ""),
|
|
36
|
-
test: {
|
|
37
|
-
"test-id": testSession?.data?.id || "",
|
|
38
|
-
"test-handle": testSession?.data?.handle || "",
|
|
39
|
-
"test-variant-id": testSession?.data?.testVariant?.id || "",
|
|
40
|
-
"test-variant-handle": testSession?.data?.testVariant?.handle || "",
|
|
41
|
-
},
|
|
42
39
|
});
|
|
43
40
|
}
|
|
41
|
+
export async function packlytics(pack, request, next) {
|
|
42
|
+
const url = new URL(request.url);
|
|
43
|
+
if (url.pathname.endsWith("/pack/track") && request.method === "POST") {
|
|
44
|
+
try {
|
|
45
|
+
await sendEvent(request, pack.session, {
|
|
46
|
+
storefrontId: pack.getPackSessionData().storeId,
|
|
47
|
+
sessionSecret: pack.session.secret,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) { }
|
|
51
|
+
return new Response(JSON.stringify({ response: "ok" }));
|
|
52
|
+
}
|
|
53
|
+
return next();
|
|
54
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-event.d.ts","sourceRoot":"","sources":["../../src/utils/send-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAsCvE,eAAO,MAAM,SAAS,iBAAkB,MAAM,aAAa,MAAM,cACzC,MAAM,gBAAgB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"send-event.d.ts","sourceRoot":"","sources":["../../src/utils/send-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAsCvE,eAAO,MAAM,SAAS,iBAAkB,MAAM,aAAa,MAAM,cACzC,MAAM,gBAAgB,gBAAgB,kCA2C7D,CAAC"}
|
package/dist/utils/send-event.js
CHANGED
|
@@ -40,7 +40,7 @@ export const sendEvent = (storefrontId, sessionId) => {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
const dataSourceName = metadata["dataSourceName"] || "analytics_events";
|
|
43
|
-
const endpointUrl = `${analyticsData.endpoint}/${analyticsData.version}/events?name=${dataSourceName}
|
|
43
|
+
const endpointUrl = `${analyticsData.endpoint}/${analyticsData.version}/events?name=${dataSourceName}`;
|
|
44
44
|
// qualified event data with payload and session id
|
|
45
45
|
const eventData = {
|
|
46
46
|
timestamp: new Date().toISOString(),
|
|
@@ -54,6 +54,7 @@ export const sendEvent = (storefrontId, sessionId) => {
|
|
|
54
54
|
method: "POST",
|
|
55
55
|
headers: {
|
|
56
56
|
"Content-Type": "application/json",
|
|
57
|
+
Authorization: `Bearer ${analyticsData.token}`,
|
|
57
58
|
},
|
|
58
59
|
body: JSON.stringify(eventData),
|
|
59
60
|
});
|