ali-ltcom-ltao-u-utils
TypeScript icon, indicating that this package has built-in type declarations

3.3.11 • Public • Published

Badges

Build status Line coverage Branch coverage TNPM version TNPM downloads


how to use

import { mtop, viewport, util, tracker } from '@ali/ltcom-ltao-u-utils';

const queryData = (params) => {
  return mtop({
    api: 'mtop.ltao.interaction.platform.api',
    v: '1.0',
    data: params
  });
}

viewport();

const {
  headerBarHeight,
  headerTotalHeight,
  nativeBackListener,
  nativeGoBack,
  openWindow,
  goldLogExp,
  goldLogClk,
} = util;

util 说明

属性 类型 描述
spmArr array [a, b]码]
isAndroid bool 是否是安卓
headerBarHeight number 头部刘海区域的高度
headerTotalHeight number 整体头部的高度
isLTApp function 返回是否是特价版
isLiteLTApp function 返回是否是特价版极简包
isOfficialLTApp function 返回是否是特价版正式包
getTtid function 获得用户的ttid
isDebugAll function 是否是debug模式
getUrlParams function(url = window.location.href) 获取url上所有query的对象
query function(name, url = window.location.href) 获取url上指定参数的值
getDataFromArray function(key, value, arr) 在数组上找到指定key=value的对象
formatBool function(value) 将value转化为bool
openLTApp function(channelId) 唤端, 自定义频道id
throttle function(fn, delay = 300) 防抖
toast function(message = '', delay = 1500, options = {}) toast防抖
goldLogExp function(key, param) 黄金令箭曝光
goldLogClk function(key, param) 黄金令箭点击
setLocalStorage function(name, value, expires) 设置ls, expires为设置过期的毫秒数
getLocalStorage function(name) 获取ls
nativeGoBack function 回退
openWindow function(link, spmc, spmd) 打开一个链接
replaceWindow function(link, spmc, spmd) replace的方式打开一个链接
nativeBackListener function 监听返回的回调事件
setCustomPageTitle function(params) 设置native的title
setNavBarStyle function(params) 设置native头部样式
setStatusBarStyle function(params) 设置状态栏样式

tracker 说明

import { tracker } from '@ali/ltcom-ltao-u-utils';

const {
  loadingStartTrigger,           // 记录loadingstart的时间,只记录不上报
  loadingEndTrigger,             // 记录loadingend的时间,只记录不上报
  firstScreenCompletedTrigger,   // 记录首屏加载完成的时间, 也会上报fsTime,只记录不上报
  fsTimeTrigger,                 // 记录fsTime的时间,优先级高于firstScreenCompleted上报的值,只记录不上报
  pushTracker,                   // 一次性上报之前记录的时间,参数为采样率的分母
} = tracker;

useEffect(() => {
  // 比如:认为 dom 出来的时候,就是loading开始的时间点
  loadingStartTrigger();
}, []);

useEffect(() => {
  // 比如:认为在页面的loading隐藏的时候,记录时间点
  if (!isLoading) {
    loadingEndTrigger();
  }
}, [isLoading]);

useEffect(() => {
  // 比如:认为请求返回的时候,认为是页面加载完成,记录时间点
  // 并发送上报的请求
  if (!isLoading) {
    firstScreenCompletedTrigger();
    pushTracker();
  }
}, [applyFinish]);
方法名 参数 描述
loadingStartTrigger (duration) 传入performance的时间长度,默认为performance.now()
loadingEndTrigger (duration) 传入performance的时间长度,默认为performance.now()
firstScreenCompletedTrigger (duration, unInteractive) 传入performance的时间长度,默认为performance.now(), unInteractive: 自动上传interactive数据,默认false,true时不上传
fsTimeTrigger (duration) 传入performance的时间长度,默认为performance.now()
pushTracker (sampling = 10) 传入采样率的分母,如传入5,则采样率为1/5 = 20%
interactiveTrigger () 手动上传interactive数据

Readme

Keywords

none

Package Sidebar

Install

npm i ali-ltcom-ltao-u-utils

Weekly Downloads

1

Version

3.3.11

License

none

Unpacked Size

372 kB

Total Files

65

Last publish

Collaborators

  • appian