@apps-in-toss/web-analytics 0.0.0-dev.1747216176095
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/README.md +3 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +94 -0
- package/package.json +37 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Primitive } from '@apps-in-toss/web-bridge';
|
|
2
|
+
|
|
3
|
+
declare const Analytics: {
|
|
4
|
+
screen: (params?: Record<string, Primitive>) => Promise<void> | undefined;
|
|
5
|
+
impression: (params?: Record<string, Primitive>) => Promise<void> | undefined;
|
|
6
|
+
click: (params?: Record<string, Primitive>) => Promise<void> | undefined;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { Analytics };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { eventLog, env, getSchemeUri } from "@apps-in-toss/web-bridge";
|
|
3
|
+
|
|
4
|
+
// src/utils/extractDateFromUUIDv7.ts
|
|
5
|
+
var extractDateFromUUIDv7 = (uuid) => {
|
|
6
|
+
const timestampHex = uuid.split("-").join("").slice(0, 12);
|
|
7
|
+
const timestamp = Number.parseInt(timestampHex, 16);
|
|
8
|
+
return new Date(timestamp);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/index.ts
|
|
12
|
+
var getReferrer = () => {
|
|
13
|
+
try {
|
|
14
|
+
const referrer = new URL(getSchemeUri());
|
|
15
|
+
return referrer.searchParams.get("referrer");
|
|
16
|
+
} catch {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var getGroupId = () => {
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(location.href);
|
|
23
|
+
if (url.protocol !== "https:") {
|
|
24
|
+
throw new Error("Invalid URL");
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
groupId: url.pathname,
|
|
28
|
+
search: url.search.startsWith("?") ? url.search.substring(1) : url.search
|
|
29
|
+
};
|
|
30
|
+
} catch {
|
|
31
|
+
return {
|
|
32
|
+
groupId: "unknown",
|
|
33
|
+
search: "unknown"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var Analytics = {
|
|
38
|
+
screen: (params = {}) => {
|
|
39
|
+
const { groupId, search } = getGroupId();
|
|
40
|
+
if (groupId === "unknown") {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return eventLog({
|
|
44
|
+
...params,
|
|
45
|
+
log_type: "screen",
|
|
46
|
+
log_name: `${groupId}::screen`,
|
|
47
|
+
params: {
|
|
48
|
+
search,
|
|
49
|
+
referrer: getReferrer(),
|
|
50
|
+
deployment_id: env.getDeploymentId(),
|
|
51
|
+
deployment_timestamp: extractDateFromUUIDv7(env.getDeploymentId()).getTime()
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
impression: (params = {}) => {
|
|
56
|
+
const { groupId, search } = getGroupId();
|
|
57
|
+
if (groupId === "unknown") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return eventLog({
|
|
61
|
+
log_type: "impression",
|
|
62
|
+
log_name: `${groupId}::impression`,
|
|
63
|
+
params: {
|
|
64
|
+
...params,
|
|
65
|
+
search,
|
|
66
|
+
referrer: getReferrer(),
|
|
67
|
+
deployment_id: env.getDeploymentId(),
|
|
68
|
+
deployment_timestamp: extractDateFromUUIDv7(env.getDeploymentId()).getTime(),
|
|
69
|
+
event_type: "impression"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
click: (params = {}) => {
|
|
74
|
+
const { groupId, search } = getGroupId();
|
|
75
|
+
if (groupId === "unknown") {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return eventLog({
|
|
79
|
+
log_type: "click",
|
|
80
|
+
log_name: `${groupId}::click`,
|
|
81
|
+
params: {
|
|
82
|
+
...params,
|
|
83
|
+
search,
|
|
84
|
+
referrer: getReferrer(),
|
|
85
|
+
deployment_id: env.getDeploymentId(),
|
|
86
|
+
deployment_timestamp: extractDateFromUUIDv7(env.getDeploymentId()).getTime(),
|
|
87
|
+
event_type: "click"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
Analytics
|
|
94
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apps-in-toss/web-analytics",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0-dev.1747216176095",
|
|
5
|
+
"description": "Web Analytics for Apps In Toss",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"prepack": "yarn build",
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"build": "tsup"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@apps-in-toss/web-bridge": "0.0.0-dev.1747216176095",
|
|
26
|
+
"tsup": "^8.3.5",
|
|
27
|
+
"typescript": "4.9.5",
|
|
28
|
+
"vitest": "^3.1.2"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@apps-in-toss/web-bridge": "*"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "b9097d25120bc711f8c90351a5c6d0346d41f7fa"
|
|
37
|
+
}
|