You need to sign in or sign up before continuing.
提交 52f2ee19 编写于 作者: O openharmony_ci 提交者: Gitee

!668 【JS 文档更改】应用打点.md 文档更改

Merge pull request !668 from lyj/master
...@@ -2,176 +2,27 @@ ...@@ -2,176 +2,27 @@
- [导入模块](#zh-cn_topic_0000001150092213_s56d19203690d4782bfc74069abb6bd71) - [导入模块](#zh-cn_topic_0000001150092213_s56d19203690d4782bfc74069abb6bd71)
- [权限](#zh-cn_topic_0000001150092213_section11257113618419) - [权限](#zh-cn_topic_0000001150092213_section11257113618419)
- [方法](#zh-cn_topic_0000001150092213_section125675489541) - [hiAppEvent.write](#zh-cn_topic_0000001150092213_section570630172512)
- [write\(string, EventType, any..., AsyncCallback<number\>\)](#zh-cn_topic_0000001150092213_section192192415554) - [hiAppEvent.write](#zh-cn_topic_0000001150092213_section0857164934517)
- [write\(string, EventType, any...\)](#zh-cn_topic_0000001150092213_section1696563334210) - [hiAppEvent.configure](#hiAppEvent.configure)
- [writeJson\(string, EventType, object, AsyncCallback<number\>\)](#zh-cn_topic_0000001150092213_section570630172512) - [ConfigOption](#ConfigOption)
- [writeJson\(string, EventType, object\)](#zh-cn_topic_0000001150092213_section0857164934517)
- [枚举](#zh-cn_topic_0000001150092213_section1978842154715)
- [EventType](#zh-cn_topic_0000001150092213_section099619567453) - [EventType](#zh-cn_topic_0000001150092213_section099619567453)
- [Event](#Event)
- [Param](#Param)
## 导入模块<a name="zh-cn_topic_0000001150092213_s56d19203690d4782bfc74069abb6bd71"></a> ## 导入模块<a name="zh-cn_topic_0000001150092213_s56d19203690d4782bfc74069abb6bd71"></a>
``` ```
import hiappevent from '@ohos.hiappevent'; import hiAppEvent from '@ohos.hiAppEvent';
``` ```
## 权限<a name="zh-cn_topic_0000001150092213_section11257113618419"></a> ## 权限<a name="zh-cn_topic_0000001150092213_section11257113618419"></a>
## 方法<a name="zh-cn_topic_0000001150092213_section125675489541"></a> ## hiAppEvent.write<a name="zh-cn_topic_0000001150092213_section570630172512"></a>
## write\(string, EventType, any..., AsyncCallback<number\>\)<a name="zh-cn_topic_0000001150092213_section192192415554"></a> write(eventName: string, eventType: EventType, keyValues: object, callback: AsyncCallback<void\>\): void
应用事件打点,将事件信息写入到当天的事件文件中,可接收类型为不定参数的事件参数,使用callback方式作为异步方法。
**参数:**
<a name="zh-cn_topic_0000001150092213_table1051173843112"></a>
<table><thead align="left"><tr id="zh-cn_topic_0000001150092213_row551638113119"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="zh-cn_topic_0000001150092213_p2512384316"><a name="zh-cn_topic_0000001150092213_p2512384316"></a><a name="zh-cn_topic_0000001150092213_p2512384316"></a>参数名</p>
</th>
<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="zh-cn_topic_0000001150092213_p1551113810318"><a name="zh-cn_topic_0000001150092213_p1551113810318"></a><a name="zh-cn_topic_0000001150092213_p1551113810318"></a>类型</p>
</th>
<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="zh-cn_topic_0000001150092213_p3519387317"><a name="zh-cn_topic_0000001150092213_p3519387317"></a><a name="zh-cn_topic_0000001150092213_p3519387317"></a>必填</p>
</th>
<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="zh-cn_topic_0000001150092213_p1351123815315"><a name="zh-cn_topic_0000001150092213_p1351123815315"></a><a name="zh-cn_topic_0000001150092213_p1351123815315"></a>说明</p>
</th>
</tr>
</thead>
<tbody><tr id="zh-cn_topic_0000001150092213_row13511538183119"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p1551838113117"><a name="zh-cn_topic_0000001150092213_p1551838113117"></a><a name="zh-cn_topic_0000001150092213_p1551838113117"></a>eventName</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p1051133893111"><a name="zh-cn_topic_0000001150092213_p1051133893111"></a><a name="zh-cn_topic_0000001150092213_p1051133893111"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p155183816314"><a name="zh-cn_topic_0000001150092213_p155183816314"></a><a name="zh-cn_topic_0000001150092213_p155183816314"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p1551173863113"><a name="zh-cn_topic_0000001150092213_p1551173863113"></a><a name="zh-cn_topic_0000001150092213_p1551173863113"></a>应用事件名称。</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001150092213_row18516388310"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p3511938103117"><a name="zh-cn_topic_0000001150092213_p3511938103117"></a><a name="zh-cn_topic_0000001150092213_p3511938103117"></a>eventType</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p55183820313"><a name="zh-cn_topic_0000001150092213_p55183820313"></a><a name="zh-cn_topic_0000001150092213_p55183820313"></a>EventType</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p13511138123117"><a name="zh-cn_topic_0000001150092213_p13511138123117"></a><a name="zh-cn_topic_0000001150092213_p13511138123117"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p75213386311"><a name="zh-cn_topic_0000001150092213_p75213386311"></a><a name="zh-cn_topic_0000001150092213_p75213386311"></a>应用事件类型。</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001150092213_row05293803113"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p1452193814313"><a name="zh-cn_topic_0000001150092213_p1452193814313"></a><a name="zh-cn_topic_0000001150092213_p1452193814313"></a>params</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p185283815313"><a name="zh-cn_topic_0000001150092213_p185283815313"></a><a name="zh-cn_topic_0000001150092213_p185283815313"></a>any...</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p25283811312"><a name="zh-cn_topic_0000001150092213_p25283811312"></a><a name="zh-cn_topic_0000001150092213_p25283811312"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p552193863115"><a name="zh-cn_topic_0000001150092213_p552193863115"></a><a name="zh-cn_topic_0000001150092213_p552193863115"></a>应用事件的参数,按顺序输入事件的参数名与参数值。参数名的类型只能为string类型,参数值的类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001150092213_row13838183316719"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p28393335711"><a name="zh-cn_topic_0000001150092213_p28393335711"></a><a name="zh-cn_topic_0000001150092213_p28393335711"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p48396339719"><a name="zh-cn_topic_0000001150092213_p48396339719"></a><a name="zh-cn_topic_0000001150092213_p48396339719"></a>AsyncCallback&lt;number&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p1783913331671"><a name="zh-cn_topic_0000001150092213_p1783913331671"></a><a name="zh-cn_topic_0000001150092213_p1783913331671"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p9749191318299"><a name="zh-cn_topic_0000001150092213_p9749191318299"></a><a name="zh-cn_topic_0000001150092213_p9749191318299"></a>回调函数,可以在回调函数中处理接口返回值。</p>
<a name="zh-cn_topic_0000001150092213_ul988644310291"></a><a name="zh-cn_topic_0000001150092213_ul988644310291"></a><ul id="zh-cn_topic_0000001150092213_ul988644310291"><li>返回值为0表示事件参数校验成功,事件正常异步写入事件文件;</li><li>大于0表示事件存在异常参数,事件在忽略异常参数后再异步写入事件文件;</li><li>小于0表示事件校验失败,不执行事件异步打点操作。</li></ul>
</td>
</tr>
</tbody>
</table>
**示例:**
```
hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strData", "strValue", (err, value) => {
if (err) {
// 事件写入异常:事件存在异常参数或者事件校验失败不执行写入
console.error(`failed to write event because ${err}`);
return;
}
// 事件写入正常
console.log(`success to write event: ${value}`);
});
```
## write\(string, EventType, any...\)<a name="zh-cn_topic_0000001150092213_section1696563334210"></a>
应用事件打点,将事件信息写入到当天的事件文件中,可接收类型为不定参数的事件参数,使用promise方式作为异步方法。
**参数:**
<a name="zh-cn_topic_0000001150092213_table1096583374216"></a>
<table><thead align="left"><tr id="zh-cn_topic_0000001150092213_row1296612339427"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="zh-cn_topic_0000001150092213_p696663354219"><a name="zh-cn_topic_0000001150092213_p696663354219"></a><a name="zh-cn_topic_0000001150092213_p696663354219"></a>参数名</p>
</th>
<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="zh-cn_topic_0000001150092213_p179660332421"><a name="zh-cn_topic_0000001150092213_p179660332421"></a><a name="zh-cn_topic_0000001150092213_p179660332421"></a>类型</p>
</th>
<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="zh-cn_topic_0000001150092213_p11966143312427"><a name="zh-cn_topic_0000001150092213_p11966143312427"></a><a name="zh-cn_topic_0000001150092213_p11966143312427"></a>必填</p>
</th>
<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="zh-cn_topic_0000001150092213_p596610331427"><a name="zh-cn_topic_0000001150092213_p596610331427"></a><a name="zh-cn_topic_0000001150092213_p596610331427"></a>说明</p>
</th>
</tr>
</thead>
<tbody><tr id="zh-cn_topic_0000001150092213_row6966113310425"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p796623344217"><a name="zh-cn_topic_0000001150092213_p796623344217"></a><a name="zh-cn_topic_0000001150092213_p796623344217"></a>eventName</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p596683319422"><a name="zh-cn_topic_0000001150092213_p596683319422"></a><a name="zh-cn_topic_0000001150092213_p596683319422"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p17966193374218"><a name="zh-cn_topic_0000001150092213_p17966193374218"></a><a name="zh-cn_topic_0000001150092213_p17966193374218"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p19661533194218"><a name="zh-cn_topic_0000001150092213_p19661533194218"></a><a name="zh-cn_topic_0000001150092213_p19661533194218"></a>应用事件名称。</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001150092213_row896623314429"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p17966153316425"><a name="zh-cn_topic_0000001150092213_p17966153316425"></a><a name="zh-cn_topic_0000001150092213_p17966153316425"></a>eventType</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p496613364212"><a name="zh-cn_topic_0000001150092213_p496613364212"></a><a name="zh-cn_topic_0000001150092213_p496613364212"></a>EventType</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p10966233134216"><a name="zh-cn_topic_0000001150092213_p10966233134216"></a><a name="zh-cn_topic_0000001150092213_p10966233134216"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p1796643344218"><a name="zh-cn_topic_0000001150092213_p1796643344218"></a><a name="zh-cn_topic_0000001150092213_p1796643344218"></a>应用事件类型。</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001150092213_row1696653315423"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p109660332428"><a name="zh-cn_topic_0000001150092213_p109660332428"></a><a name="zh-cn_topic_0000001150092213_p109660332428"></a>params</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p1396663313428"><a name="zh-cn_topic_0000001150092213_p1396663313428"></a><a name="zh-cn_topic_0000001150092213_p1396663313428"></a>any...</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p1196673354215"><a name="zh-cn_topic_0000001150092213_p1196673354215"></a><a name="zh-cn_topic_0000001150092213_p1196673354215"></a></p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p199671338422"><a name="zh-cn_topic_0000001150092213_p199671338422"></a><a name="zh-cn_topic_0000001150092213_p199671338422"></a>应用事件的参数,按顺序输入事件的参数名与参数值。参数名的类型只能为string类型,参数值的类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。</p>
</td>
</tr>
</tbody>
</table>
**返回值:**
<a name="zh-cn_topic_0000001150092213_table106721328171713"></a>
<table><thead align="left"><tr id="zh-cn_topic_0000001150092213_row9672122817176"><th class="cellrowborder" valign="top" width="26.06%" id="mcps1.1.3.1.1"><p id="zh-cn_topic_0000001150092213_p106728288171"><a name="zh-cn_topic_0000001150092213_p106728288171"></a><a name="zh-cn_topic_0000001150092213_p106728288171"></a>类型</p>
</th>
<th class="cellrowborder" valign="top" width="73.94%" id="mcps1.1.3.1.2"><p id="zh-cn_topic_0000001150092213_p5672112817178"><a name="zh-cn_topic_0000001150092213_p5672112817178"></a><a name="zh-cn_topic_0000001150092213_p5672112817178"></a>说明</p>
</th>
</tr>
</thead>
<tbody><tr id="zh-cn_topic_0000001150092213_row06721528191711"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001150092213_p107821612171919"><a name="zh-cn_topic_0000001150092213_p107821612171919"></a><a name="zh-cn_topic_0000001150092213_p107821612171919"></a>Promise&lt;void&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001150092213_p4672828141718"><a name="zh-cn_topic_0000001150092213_p4672828141718"></a><a name="zh-cn_topic_0000001150092213_p4672828141718"></a>Promise函数</p>
</td>
</tr>
</tbody>
</table>
**示例:**
```
hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strData", "strValue")
.then((value) => {
// 事件写入正常
console.log(`success to write event: ${value}`);
}).catch((err) => {
// 事件写入异常:事件存在异常参数或者事件校验失败不执行写入
console.error(`failed to write event because ${err}`);
});
```
## writeJson\(string, EventType, object, AsyncCallback<number\>\)<a name="zh-cn_topic_0000001150092213_section570630172512"></a>
应用事件打点,将事件信息写入到当天的事件文件中,可接收类型为JSON对象的事件参数,使用callback方式作为异步方法。 应用事件打点,将事件信息写入到当天的事件文件中,可接收类型为JSON对象的事件参数,使用callback方式作为异步方法。
...@@ -206,7 +57,7 @@ hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strDa ...@@ -206,7 +57,7 @@ hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strDa
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p754216544454"><a name="zh-cn_topic_0000001150092213_p754216544454"></a><a name="zh-cn_topic_0000001150092213_p754216544454"></a>应用事件类型。</p> <td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p754216544454"><a name="zh-cn_topic_0000001150092213_p754216544454"></a><a name="zh-cn_topic_0000001150092213_p754216544454"></a>应用事件类型。</p>
</td> </td>
</tr> </tr>
<tr id="zh-cn_topic_0000001150092213_row354265418456"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p1354215547452"><a name="zh-cn_topic_0000001150092213_p1354215547452"></a><a name="zh-cn_topic_0000001150092213_p1354215547452"></a>jsonParam</p> <tr id="zh-cn_topic_0000001150092213_row354265418456"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p1354215547452"><a name="zh-cn_topic_0000001150092213_p1354215547452"></a><a name="zh-cn_topic_0000001150092213_p1354215547452"></a>keyValues</p>
</td> </td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p754225416456"><a name="zh-cn_topic_0000001150092213_p754225416456"></a><a name="zh-cn_topic_0000001150092213_p754225416456"></a>object</p> <td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p754225416456"><a name="zh-cn_topic_0000001150092213_p754225416456"></a><a name="zh-cn_topic_0000001150092213_p754225416456"></a>object</p>
</td> </td>
...@@ -217,12 +68,12 @@ hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strDa ...@@ -217,12 +68,12 @@ hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strDa
</tr> </tr>
<tr id="zh-cn_topic_0000001150092213_row87751758579"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p777595810712"><a name="zh-cn_topic_0000001150092213_p777595810712"></a><a name="zh-cn_topic_0000001150092213_p777595810712"></a>callback</p> <tr id="zh-cn_topic_0000001150092213_row87751758579"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p777595810712"><a name="zh-cn_topic_0000001150092213_p777595810712"></a><a name="zh-cn_topic_0000001150092213_p777595810712"></a>callback</p>
</td> </td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p1577513581719"><a name="zh-cn_topic_0000001150092213_p1577513581719"></a><a name="zh-cn_topic_0000001150092213_p1577513581719"></a>AsyncCallback&lt;number&gt;</p> <td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p1577513581719"><a name="zh-cn_topic_0000001150092213_p1577513581719"></a><a name="zh-cn_topic_0000001150092213_p1577513581719"></a>AsyncCallback&lt;void&gt;</p>
</td> </td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p157753585718"><a name="zh-cn_topic_0000001150092213_p157753585718"></a><a name="zh-cn_topic_0000001150092213_p157753585718"></a></p> <td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001150092213_p157753585718"><a name="zh-cn_topic_0000001150092213_p157753585718"></a><a name="zh-cn_topic_0000001150092213_p157753585718"></a></p>
</td> </td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p1065434111303"><a name="zh-cn_topic_0000001150092213_p1065434111303"></a><a name="zh-cn_topic_0000001150092213_p1065434111303"></a>回调函数,可以在回调函数中处理接口返回值。</p> <td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p1065434111303"><a name="zh-cn_topic_0000001150092213_p1065434111303"></a><a name="zh-cn_topic_0000001150092213_p1065434111303"></a>回调函数,可以在回调函数中处理接口返回值。</p>
<a name="zh-cn_topic_0000001150092213_ul182248492307"></a><a name="zh-cn_topic_0000001150092213_ul182248492307"></a><ul id="zh-cn_topic_0000001150092213_ul182248492307"><li>返回值为0表示事件参数校验成功,事件正常异步写入事件文件;</li><li>大于0表示事件存在异常参数,事件在忽略异常参数后再异步写入事件文件;</li><li>小于0表示事件校验失败,不执行事件异步打点操作</li></ul> <a name="zh-cn_topic_0000001150092213_ul182248492307"></a><a name="zh-cn_topic_0000001150092213_ul182248492307"></a><ul id="zh-cn_topic_0000001150092213_ul182248492307"><li>返回值为0表示事件参数校验成功,事件正常异步写入事件文件;</li><li>大于0表示事件校验存在异常参数,事件在忽略异常参数后将事件异步写入事件文件;</li><li>小于0表示事件校验失败,不将事件写入事件文件</li></ul>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -231,10 +82,10 @@ hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strDa ...@@ -231,10 +82,10 @@ hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strDa
**示例:** **示例:**
``` ```
hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "strData":"strValue"}, (err, value) => { hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"}, (err, value) => {
if (err) { if (err) {
// 事件写入异常:事件存在异常参数或者事件校验失败不执行写入 // 事件写入异常:事件存在异常参数或者事件校验失败不执行写入
console.error(`failed to write event because ${err}`); console.error(`failed to write event because ${err.code}`);
return; return;
} }
...@@ -243,13 +94,16 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s ...@@ -243,13 +94,16 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s
}); });
``` ```
## writeJson\(string, EventType, object\)<a name="zh-cn_topic_0000001150092213_section0857164934517"></a> ## hiAppEvent.write<a name="zh-cn_topic_0000001150092213_section0857164934517"></a>
write(eventName: string, eventType: EventType, keyValues: object): Promise<void\>
应用事件打点,将事件信息写入到当天的事件文件中,可接收类型为JSON对象的事件参数,使用promise方式作为异步方法。 应用事件打点,将事件信息写入到当天的事件文件中,可接收类型为JSON对象的事件参数,使用promise方式作为异步方法。
**参数:** **参数:**
<a name="zh-cn_topic_0000001150092213_table11857249104514"></a> <a name="zh-cn_topic_0000001150092213_table11857249104514"></a>
<table><thead align="left"><tr id="zh-cn_topic_0000001150092213_row198584493457"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="zh-cn_topic_0000001150092213_p128580494453"><a name="zh-cn_topic_0000001150092213_p128580494453"></a><a name="zh-cn_topic_0000001150092213_p128580494453"></a>参数名</p> <table><thead align="left"><tr id="zh-cn_topic_0000001150092213_row198584493457"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="zh-cn_topic_0000001150092213_p128580494453"><a name="zh-cn_topic_0000001150092213_p128580494453"></a><a name="zh-cn_topic_0000001150092213_p128580494453"></a>参数名</p>
</th> </th>
<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="zh-cn_topic_0000001150092213_p2085813494456"><a name="zh-cn_topic_0000001150092213_p2085813494456"></a><a name="zh-cn_topic_0000001150092213_p2085813494456"></a>类型</p> <th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="zh-cn_topic_0000001150092213_p2085813494456"><a name="zh-cn_topic_0000001150092213_p2085813494456"></a><a name="zh-cn_topic_0000001150092213_p2085813494456"></a>类型</p>
...@@ -278,7 +132,7 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s ...@@ -278,7 +132,7 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p198581349194515"><a name="zh-cn_topic_0000001150092213_p198581349194515"></a><a name="zh-cn_topic_0000001150092213_p198581349194515"></a>应用事件类型。</p> <td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001150092213_p198581349194515"><a name="zh-cn_topic_0000001150092213_p198581349194515"></a><a name="zh-cn_topic_0000001150092213_p198581349194515"></a>应用事件类型。</p>
</td> </td>
</tr> </tr>
<tr id="zh-cn_topic_0000001150092213_row78580497453"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p2085819494459"><a name="zh-cn_topic_0000001150092213_p2085819494459"></a><a name="zh-cn_topic_0000001150092213_p2085819494459"></a>jsonParam</p> <tr id="zh-cn_topic_0000001150092213_row78580497453"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001150092213_p2085819494459"><a name="zh-cn_topic_0000001150092213_p2085819494459"></a><a name="zh-cn_topic_0000001150092213_p2085819494459"></a>keyValues</p>
</td> </td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p8859749154519"><a name="zh-cn_topic_0000001150092213_p8859749154519"></a><a name="zh-cn_topic_0000001150092213_p8859749154519"></a>object</p> <td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001150092213_p8859749154519"><a name="zh-cn_topic_0000001150092213_p8859749154519"></a><a name="zh-cn_topic_0000001150092213_p8859749154519"></a>object</p>
</td> </td>
...@@ -301,26 +155,66 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s ...@@ -301,26 +155,66 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s
</thead> </thead>
<tbody><tr id="zh-cn_topic_0000001150092213_row1181161019479"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001150092213_p15811181004712"><a name="zh-cn_topic_0000001150092213_p15811181004712"></a><a name="zh-cn_topic_0000001150092213_p15811181004712"></a>Promise&lt;void&gt;</p> <tbody><tr id="zh-cn_topic_0000001150092213_row1181161019479"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001150092213_p15811181004712"><a name="zh-cn_topic_0000001150092213_p15811181004712"></a><a name="zh-cn_topic_0000001150092213_p15811181004712"></a>Promise&lt;void&gt;</p>
</td> </td>
<td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001150092213_p14811710164718"><a name="zh-cn_topic_0000001150092213_p14811710164718"></a><a name="zh-cn_topic_0000001150092213_p14811710164718"></a>Promise函数</p> <td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001150092213_p14811710164718"><a name="zh-cn_topic_0000001150092213_p14811710164718"></a><a name="zh-cn_topic_0000001150092213_p14811710164718"></a>Promise实例,可以在其then()、catch()方法中分别对事件写入成功、写入异常的情况进行回调处理。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
**示例:** **示例:**
``` ```
hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "strData":"strValue"}) hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"})
.then((value) => { .then((value) => {
// 事件写入正常 // 事件写入正常
console.log(`success to write event: ${value}`); console.log(`success to write event: ${value}`);
}).catch((err) => { }).catch((err) => {
// 事件写入异常:事件存在异常参数或者事件校验失败不执行写入 // 事件写入异常:事件存在异常参数或者事件校验失败不执行写入
console.error(`failed to write event because ${err}`); console.error(`failed to write event because ${err.code}`);
}); });
``` ```
## 枚举<a name="zh-cn_topic_0000001150092213_section1978842154715"></a> ## hiAppEvent.configure
configure(config: ConfigOption): boolean
应用事件打点配置方法,可用于配置打点开关、文件目录存储限额大小等功能。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------ | ---- | ------------------------ |
| config | ConfigOption | 是 | 应用事件打点配置项对象。 |
**返回值:**
| 类型 | 说明 |
| ------- | ----------------------------------------------- |
| boolean | 配置结果,true表示配置成功,false表示配置失败。 |
**示例:**
```
// 配置应用事件打点功能开关
hiAppEvent.configure({
disable: true
})
// 配置事件文件目录存储限额大小
hiAppEvent.configure({
maxStorage: '100M'
})
```
## ConfigOption
此接口提供了应用打点的配置选项。
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------- | ---- | ------------------------------------------------------------ |
| disable | boolean | 否 | 应用打点功能开关。配置值为true表示关闭打点功能,false表示不关闭打点功能。 |
| maxStorage | string | 否 | 打点数据本地存储文件所在目录的配额大小,默认限额为“10M”。所在目录大小超出限额后会对目录进行清理操作,会按从旧到新的顺序逐个删除打点数据文件,直到目录大小不超出限额时停止。 |
## EventType<a name="zh-cn_topic_0000001150092213_section099619567453"></a> ## EventType<a name="zh-cn_topic_0000001150092213_section099619567453"></a>
...@@ -366,3 +260,26 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s ...@@ -366,3 +260,26 @@ hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "s
</tbody> </tbody>
</table> </table>
## Event
此接口提供了所有预定义事件的事件名称常量。
**属性:**
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------------------- | -------- | ---- | ---- | -------------------- |
| USER_LOGIN | string | 是 | 否 | 用户登录事件。 |
| USER_LOGOUT | string | 是 | 否 | 用户登出事件。 |
| DISTRIBUTED_SERVICE_START | string | 是 | 否 | 分布式服务启动事件。 |
## Param
此接口提供了所有预定义参数的参数名称常量。
**属性:**
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------------------------- | -------- | ---- | ---- | ------------------ |
| USER_ID | string | 是 | 否 | 用户自定义ID。 |
| DISTRIBUTED_SERVICE_NAME | string | 是 | 否 | 分布式服务名称。 |
| DISTRIBUTED_SERVICE_INSTANCE_ID | string | 是 | 否 | 分布式服务实例ID。 |
文件模式从 100644 更改为 100755
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册