golcer-analysis-web
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

高策数据分析 Web SDK

高策数据分析(Golcer Data Analysis)缩写 GDA

集成准备

  1. 向高策相关人员申请 AppKey
  2. 下载安装
npm install golcer-analysis-web --save

支持 jsDelivr

<script src="https://cdn.jsdelivr.net/npm/golcer-analysis-web@latest"></script>

快速集成

import GDA from 'golcer-analysis-web'

GDA.init({
  appKey: '通过高策申请获取的 AppKey',
  autoTrack: false, // 是否自动上报,单页应用关闭此项通过主动上报 PV
  logger: true // 设置为 true 后会在控制台显示发送的数据
})

API

GDA.init(Object config)

参数

属性 类型 默认值 必填 说明
appKey string 通过高策申请获取的 AppKey
autoTrack boolean true 是否自动上报,单页应用关闭此项通过主动上报 PV
logger boolean 设置为 true 后会在控制台显示发送的数据

GDA.pageView()

主动触发 PV($Web_page_view) 事件

GDA.track(String eventName, Object data)

上报自定义事件

参数

参数 类型 默认值 必填 说明
eventName string 自定义事件英文名
Data object 自定义事件属性

GDA.setUserID(String userID)

设置用户 ID

GDA.setUserProfile(Object data)

直接设置用户的属性,如果存在则覆盖。

GDA.setUserOnceProfile(Object data)

如果不存在则设置,存在就不设置。

GDA.setUserIncrementProfile(Object data)

对当前用户的属性做递增或者递减。

// 表示 attrname 递减
gda.setUserIncrementProfile({ attrname: -1 });
// 表示 attrname 递增
gda.setUserIncrementProfile({ attrname: 1 });

GDA.setUserAppendProfile(Object data)

给数组属性添加值。通过 setProfile 只能改变属性的值。如果这个属性是数组类型的,你不想完全改变这个值,只想做添加操作可以使用此方法。

预置事件

事件名 事件显示名 事件属性 属性类型 说明
$Web_page_view 浏览页面 $title string 页面 <title> 标签的内容
- - $host string 页面地址域名,服务端解析 request headers host
- - $path string 页面路径,不含域名
- - $search string URL query 参数,如:https://example.com?a=1&b=2 中的 a=1&b=2
- - $url_hash string URL hash 值,如:https://example.com/#top 中的 #top
- - $referrer_host string 前向地址的域名
- - $referrer_path string 前向地址的路径
- - $referrer_search string 前向地址的 search 部分
$Web_user_click 元素点击事件 $element_type string 元素标签名
- - $element_content string 元素内容
$element_selector string 元素 css 选择器

所有事件都有的预置属性

属性名 属性类型 说明
$is_first_time boolean 新用户首次访问页面时,触发的第一个 PV ,该属性值为 true,后续再触发 PV 事件时,该属性都为 false
$lib_version string SDK 版本号,请求参数中的 version
$screen_width number 屏幕宽度
$screen_height number 屏幕高度
$ip string IP,服务端通过 HTTP 请求得到
$timezone_offset number 时区偏移量
$title string 页面 <title> 标签的内容
$url_query object URL query,如:https://example.com/a=1&b=2{ a: "1", b: "2" }

Readme

Keywords

Package Sidebar

Install

npm i golcer-analysis-web

Weekly Downloads

2

Version

0.2.1

License

ISC

Unpacked Size

37.2 kB

Total Files

8

Last publish

Collaborators

  • goldentec