1.0.5 • Published 1 year ago

@rulaicd-lining/vue-log v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

vue-log

Vue log plugin

automate record page navigate info with vue-router guard(afterEach), also you can record the log manually.

How to Use

  1. Install package from npm
npm install @rulaicd-lining/vue-log

Or with yarn

yarn add @rulaicd-lining/vue-log
  1. import to vue project and use it
import logs from '@rulaicd-lining/vue-log'

// 数据埋点插件
Vue.use(logs, {
    router, // vue-router
    app: 'app_name',
    endpoint: 'request endpoint',
    secure: 'request security key',
    get userId() {
        return 'current login userId'
    },
    get orgId() {
        return 'current login user orgId'
    },
})

Configration

fieldtyperequiredremark
routervue-router instancetruevue-rouer for navigate info automated record
appstringfalseapp name, default: main
endpointstringtrueendpoint for logs submit to
securestringtrueserver side security key
userIdstring/numberfalsegetter for current login user Id
orgIdstring/numberfalsegetter for current login user orgId
intervalnumberfalselog buffer time, default: 2s
usePathbooleanfalseuse router path instead of name, default: false
routeNameFormatterfunctionfalseformat route name

Log Datastruct

Logs will post to endpoint with post method use axios, like:

await axios({
  url: endpoint,
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  params: { secure, ts },
  data: { logs },
})

Query

fieldtyperequiredremark
securestringtruemd5 hash string
tsnumbertruetimestamp with millisecond

Post body

{ "logs": [ log ] }

log document fields: |field|type|required|default|remark| |---|---|---|---|---| |app|string|true|main|app name| |page|string|true|--|current page name| |source|string|true|--|current operate source| |action|enum|true|--|current operation| |ts|number|true|Date.now()|log timestamp| |orgId|string|false|--|login user orgId| |userId|string|false|--|login user id| |extra|any|false|--|extra data info|

action enum |field|description| |---|---| |view|page view| |new|create source| |edit|edit source| |delete|delete source| |navigate|router navigate with extra data: { to: 'navigate to name', duration: 'page stay duration' }| |click|click event| |request|server request|

Secure md5 Hash

secure field hashed by md5 with timestamp, there is the algorithm

secure = md5(secure + Date.now())

The secure field will available in next 10 seconds, so our request must finished in 10 seconds.

Methods

vue-log can automated log the navigation info by every navigate success. but we can manually do the log by action.

Every action method will return a object with a flush method to flush logs immediately.

  • in vue template
<template>
  <button name="add" @click="$log.click('AddButton')"></button>
</template>
  • in vue component
this.$log.click('AddButton')

// flush immediately
this.$log.click('AddButton').flush()

method signature

type method = 'view' | 'edit' | 'new' | 'delete' | 'navigate' | 'click' | 'request'

this.$log[method](source: string, extra: any): void
1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago