1.0.0 • Published 3 years ago

databee v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

databee

终端数据采集器

安装

npm i -S databee

初始化

import databee, { actions, dimensions } from 'databee';


const run = async () => {
  // 初始化
  await databee.init();

};

run();

设置基础维度

const run = () => {
  // 设置公共基础维度
  databee.set({
    device: {
      brand: '',
      model: '',
      uuid: '',
      mac: '',
      os: '',
      osVersion: '',
      screenWidth: '',
      screenHeight: '',
      pixelRatio: '',
    },
    network: {
      type: '',
      ip: '',
    },
    app: {
      type: '',
      name: '',
      version: '',
    },
  });

  // 单独设置用户公共信息
  databee.set({
    user: {
      login: '',
      name: '',
      id: '',
    }
  })

}

数据采集

const run = async() => {
  // 数据采集、暂存; 传入的数据会和公共维度数据浅合并,形成完整的采集数据
  await databee.take({
    scene: {
      name: '',
      desc: '',
    },
    event: {
      name: '',
      desc: '',
    },
    position: {
      module: '',
      page: '',
      area: '',
      element: '',
    },
    action: {
      name: actions.request.send,
      desc: '',
    },
    // 业务数据
    data: {

    }
  });
}

数据查询

import dayjs from 'dayjs';
const run = async() => {

  // 默认参数
  const range = {
    start: '',
    end: dayjs().valueOf()
  }

  // 使用默认参数
  const res = await databee.find();
  console.log('res', res);

  // 使用自定义参数
  const res = await databee.find(range);
  console.log('res', res);
}

数据定时自动过期清除

const run = async() => {
  // 默认参数
  const expire = {
    expireTime: 24, // 过期时间 24h
    unit: 'hour', // hour | minute | second | millisecond
    auto: true, // 自动过期, 开启会定时清除24h以前的数据
  }

  // 使用默认过期时间 expire
  await databee.expire();

  // 自定义数据过期时间
  await databee.expire(expire);
}

数据全部清除

const run = () => {
  // 清除所有数据
  await databee.clear();
}