@aem-sdk/tracker-plugin-event-timing 0.1.0-beta.0
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 +21 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @aem-sdk/tracker-plugin-event-timing
|
|
2
|
+
|
|
3
|
+
Browser Event Timing 插件。保留旧 `@ali/aes-tracker-plugin-eventTiming` 的核心采集能力。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @aem-sdk/tracker @aem-sdk/tracker-plugin-event-timing@next
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 用法
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import AES from "@aem-sdk/tracker";
|
|
15
|
+
import EventTimingPlugin from "@aem-sdk/tracker-plugin-event-timing";
|
|
16
|
+
|
|
17
|
+
const aes = new AES({ pid: "demo" });
|
|
18
|
+
aes.use(EventTimingPlugin);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
插件只在注册后监听 Event Timing API,不会在 import 时注册 listener、创建 observer 或发送日志。上报字段直接使用新平台最终存储字段:`p1` 为 `startTime`,`p2` 为 `duration`,`p3` 为触发节点 selector,`p4` 为事件名,`p5` 为 `processingStart`,`p6` 为 `processingEnd`,`p7` 表示是否为 FID。
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){if(!e)return;if(Object.prototype.toString.call(e)===`[object Array]`)return t(e);let n=[],r=e;for(;r;)n.push(r),r=r.parentNode;return t(n)}function t(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(typeof window<`u`&&r===window||typeof document<`u`&&r===document)break;let i=r;if(i.id){t.push(`#${String(i.id)}`);break}if(typeof i.className==`string`&&i.className){let e=i.className.split(/\s+/).filter(e=>!!e).join(`.`);if(e){t.push(`.${e}`);continue}}i.nodeName&&t.push(String(i.nodeName))}return t.reverse().join(` `)||void 0}const n={durationThreshold:100,type:`event`},r={buffered:!0,type:`first-input`},i=e=>{if(!a())return;let t=o();if(!t)return;let i,f=null,p=(t,n)=>{u(()=>{l(e,t,!!n)})};try{i=new t(e=>{let t=e.getEntries().filter(s),n=t.filter(e=>e.interactionId!==0).reduce((e,t)=>{let n=String(t.interactionId);return e[n]||(e[n]=[]),e[n].push(t),e},{});Object.keys(n).forEach(e=>{let t=n[e];p(t[t.length-1])}),t.filter(e=>e.interactionId===0).forEach(e=>{p(e)})}),i.observe(n)}catch(e){return}if(c(t))try{f=new t((e,t)=>{p(e.getEntries()[0],!0),t.disconnect(),f=null}),f.observe(r)}catch(e){f=null}d(e=>{if(!e){f==null||f.disconnect(),i.disconnect();return}setTimeout(()=>{try{i.observe(n)}catch(e){return}},100)})};function a(){return typeof window<`u`&&typeof document<`u`&&window.PerformanceEventTiming!==void 0}function o(){if(typeof window>`u`)return;let e=window.PerformanceObserver;return typeof e==`function`?e:void 0}function s(e){return e.interactionId!==void 0&&!!e.processingStart&&!!e.processingEnd&&Number(e.processingEnd)-Number(e.processingStart)>1}function c(e){return(e.supportedEntryTypes||[]).indexOf(`first-input`)!==-1}function l(t,n,r){if(n)try{t.log(`eventTiming`,{p1:n.startTime,p2:n.duration,p3:e(n.target),p4:n.name,p5:n.processingStart,p6:n.processingEnd,p7:r?`1`:`0`})}catch(e){return}}function u(e){try{let t=globalThis.requestIdleCallback;if(typeof t==`function`){t(e,{timeout:1e3});return}}catch(e){}setTimeout(e,0)}function d(e){let t=f();if(t)try{document.addEventListener(t.eventName,()=>{e(!document[t.hidden])})}catch(e){return}}function f(){if(typeof document>`u`)return;if(document.hidden!==void 0)return{eventName:`visibilitychange`,hidden:`hidden`};let e=document;if(e.webkitHidden!==void 0)return{eventName:`webkitvisibilitychange`,hidden:`webkitHidden`};if(e.msHidden!==void 0)return{eventName:`msvisibilitychange`,hidden:`msHidden`}}module.exports=i;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AESPluginFactory } from "@aem-sdk/tracker";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface EventTimingPluginOptions {}
|
|
5
|
+
declare const AESPluginEventTiming: AESPluginFactory<void, EventTimingPluginOptions>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { EventTimingPluginOptions, AESPluginEventTiming as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){if(!e)return;if(Object.prototype.toString.call(e)===`[object Array]`)return t(e);let n=[],r=e;for(;r;)n.push(r),r=r.parentNode;return t(n)}function t(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(typeof window<`u`&&r===window||typeof document<`u`&&r===document)break;let i=r;if(i.id){t.push(`#${String(i.id)}`);break}if(typeof i.className==`string`&&i.className){let e=i.className.split(/\s+/).filter(e=>!!e).join(`.`);if(e){t.push(`.${e}`);continue}}i.nodeName&&t.push(String(i.nodeName))}return t.reverse().join(` `)||void 0}const n={durationThreshold:100,type:`event`},r={buffered:!0,type:`first-input`},i=e=>{if(!a())return;let t=o();if(!t)return;let i,f=null,p=(t,n)=>{u(()=>{l(e,t,!!n)})};try{i=new t(e=>{let t=e.getEntries().filter(s),n=t.filter(e=>e.interactionId!==0).reduce((e,t)=>{let n=String(t.interactionId);return e[n]||(e[n]=[]),e[n].push(t),e},{});Object.keys(n).forEach(e=>{let t=n[e];p(t[t.length-1])}),t.filter(e=>e.interactionId===0).forEach(e=>{p(e)})}),i.observe(n)}catch(e){return}if(c(t))try{f=new t((e,t)=>{p(e.getEntries()[0],!0),t.disconnect(),f=null}),f.observe(r)}catch(e){f=null}d(e=>{if(!e){f==null||f.disconnect(),i.disconnect();return}setTimeout(()=>{try{i.observe(n)}catch(e){return}},100)})};function a(){return typeof window<`u`&&typeof document<`u`&&window.PerformanceEventTiming!==void 0}function o(){if(typeof window>`u`)return;let e=window.PerformanceObserver;return typeof e==`function`?e:void 0}function s(e){return e.interactionId!==void 0&&!!e.processingStart&&!!e.processingEnd&&Number(e.processingEnd)-Number(e.processingStart)>1}function c(e){return(e.supportedEntryTypes||[]).indexOf(`first-input`)!==-1}function l(t,n,r){if(n)try{t.log(`eventTiming`,{p1:n.startTime,p2:n.duration,p3:e(n.target),p4:n.name,p5:n.processingStart,p6:n.processingEnd,p7:r?`1`:`0`})}catch(e){return}}function u(e){try{let t=globalThis.requestIdleCallback;if(typeof t==`function`){t(e,{timeout:1e3});return}}catch(e){}setTimeout(e,0)}function d(e){let t=f();if(t)try{document.addEventListener(t.eventName,()=>{e(!document[t.hidden])})}catch(e){return}}function f(){if(typeof document>`u`)return;if(document.hidden!==void 0)return{eventName:`visibilitychange`,hidden:`hidden`};let e=document;if(e.webkitHidden!==void 0)return{eventName:`webkitvisibilitychange`,hidden:`webkitHidden`};if(e.msHidden!==void 0)return{eventName:`msvisibilitychange`,hidden:`msHidden`}}export{i as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aem-sdk/tracker-plugin-event-timing",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "AEM Web SDK browser event timing plugin",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"registry": "https://registry.npmjs.org"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@aem-sdk/tracker": "0.1.0-beta.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@aem-sdk/tracker": "^0.1.0-beta.0"
|
|
31
|
+
},
|
|
32
|
+
"aemSizeBudget": {
|
|
33
|
+
"gzipBytes": 3072
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"clean": "rm -rf dist dist-types",
|
|
38
|
+
"typecheck": "tsc -b tsconfig.json"
|
|
39
|
+
}
|
|
40
|
+
}
|