Skip to content

Commit

Permalink
style: update
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyuxuan committed Aug 16, 2022
1 parent 47f6fc0 commit c2b4b91
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
// Extension configs
"cSpell.words": [
"antfu",
"dpss",
"pnpm",
"Tian",
"ttfb",
"vitegil"
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Vitegil SDK
# Vitegil SDK 💉

[![npm](https://img.shields.io/npm/v/vitegil-sdk?color=3c8cff)](https://www.npmjs.com/package/vitegil-sdk)
[![node compatibility](https://img.shields.io/node/v/vitegil-sdk?color=0F9D58)](https://nodejs.org/en/about/releases/)
Expand Down
59 changes: 28 additions & 31 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>

<body>
<script src="./dist/index.js"></script>
<body>
<script src="./dist/index.js"></script>

<button data-tracker-key="btn">btn to add</button>
<button id="tracker-history">history</button>
<button data-tracker-key="btn">btn to add</button>
<button id="tracker-history">history</button>

<script>
// eslint-disable-next-line no-undef
new Tracker({
requestUrl: 'https://koa-template-382-4-1312741325.sh.run.tcloudbase.com/api/test',
historyTracker: true,
domTracker: true,
jsError: true,
lazyReport: true,
timeTracker: true,
deviceTracker: true,
})
const btn = document.querySelector('#tracker-history')
btn.addEventListener('click', () => {
history.replaceState('abc', '')
})

// getDeviceData(window)
</script>
</body>

</html>
<script>
// eslint-disable-next-line no-undef
new Tracker({
requestUrl: 'https://koa-template-382-4-1312741325.sh.run.tcloudbase.com/api/test',
historyTracker: true,
domTracker: true,
jsError: true,
lazyReport: true,
timeTracker: true,
deviceTracker: true,
})
const btn = document.querySelector('#tracker-history')
btn.addEventListener('click', () => {
history.replaceState('abc', '')
})
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class Tracker {
event: 'uv-event',
targetKey: 'uv-event',
data: this.data.uuid,
}, 'useruv', true)
}, 'userid', true)
return
}
this.sendTracker({
Expand Down Expand Up @@ -189,7 +189,7 @@ export default class Tracker {
*/
private jsErrorEvent(): void {
window.addEventListener('error', (e) => {
if (this.isResourseError(e))
if (this.isResourceError(e))
return
if (this.data.lazyReport) {
this.saveTracker({
Expand Down Expand Up @@ -222,7 +222,7 @@ export default class Tracker {
* @param event 事件对象
* @returns boolean 是否是资源错误
*/
private isResourseError(event: ErrorEvent): boolean {
private isResourceError(event: ErrorEvent): boolean {
const target = event.target || event.srcElement
const isElementTarget = target instanceof HTMLScriptElement || target instanceof HTMLLinkElement || target instanceof HTMLImageElement
if (!isElementTarget)
Expand Down
5 changes: 2 additions & 3 deletions src/lib/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function getLanguage(navigator: any) {
return navigator.browserLanguage || navigator.language
}

function getOrientationStatu(_window: any) {
function getOrientationStatus(_window: any) {
let orientationStatus = ''
const orientation = _window.matchMedia('(orientation: portrait)')
if (orientation.matches)
Expand Down Expand Up @@ -172,11 +172,10 @@ export function getDeviceData() {
screenWidth: _window.screen.width,
language: getLanguage(navigator),
netWork: getNetwork(navigator),
orientation: getOrientationStatu(_window),
orientation: getOrientationStatus(_window),
browser: getValue(map, BrowserType),
browserInfo: getBrowserInfo(map, ua),
}
// console.log(data)
return data
}
else {
Expand Down
1 change: 0 additions & 1 deletion src/lib/fmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export default class FMPTiming {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const resultEls: FMP.Els = this.filterResult(tp.els)
console.log('最终节点集合', tp, resultEls)
const fmpTiming: number = this.getFmpTime(resultEls)
saveToStorage({ firstMeaningfulPaint: fmpTiming }, 'performance')

Expand Down
2 changes: 0 additions & 2 deletions src/utils/fingerprinting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ export default function fingerprinting(): string {
// 通过sha256算法得出唯一的canvas指纹
const fingerprint: string = CryptoES.SHA256(canvasImageData).toString()

console.log(`指纹 ${fingerprint}`)

return fingerprint
}
2 changes: 1 addition & 1 deletion src/utils/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const reportStorageInfo = (url: string) => {
const time = localStorage.getItem('timing') || undefined
time && reportData.push(time)

const uv = localStorage.getItem('useruv') || undefined
const uv = localStorage.getItem('userid') || undefined
uv && reportData.push(uv)

const device = localStorage.getItem('device') || undefined
Expand Down

0 comments on commit c2b4b91

Please sign in to comment.