@acpaas-ui/ngx-analytics 中文文档教程
@acpaas-ui/ngx-analytics
该服务在 Google Analytics ga()
函数之上添加了一个 Angular 层。
Usage
import { AnalyticsModule } from '@acpaas-ui/ngx-analytics';
Documentation
访问我们的文档网站,获取完整的操作文档和指南
Analytics service
Methods
Method | Description |
---|---|
setDimension(key: string, value: string) | Send a custom dimension. More info on dimensions and its parameters can be found in the Google Analytics documentation. |
triggerPageView(title?: string, location?: string, page?: string) | Trigger a page view with optional custom parameters. More info on page tracking and its parameters can be found in the Google Analytics documentation. |
triggerEvent(category: string, action: string, label?: string, value?: any) | Trigger an event with optional custom parameters. Usually the category is the tagname of the element. More info on event tracking and its parameters can be found in the Google Analytics documentation. |
Example
import { AnalyticsModule } from '@acpaas-ui/ngx-analytics';
@NgModule({
imports: [
AnalyticsModule
]
});
export class AppModule {};
默认情况下,每次路线更改都有一个页面触发器。 要为特定路线禁用此功能,请将 doNotTrack: true
添加到 app-routing.module.ts
中的路线数据。
{
path: 'home',
component: HomePage,
data: {
doNotTrack: true
}
}
import { GAService } from '@acpaas-ui/ngx-analytics';
constructor(
private gaService: GAService
) {}
Set dimension
this.gaService.setDimension('some-dimension', 'some-value');
Trigger page view
使用默认参数:
this.gaService.triggerPageView();
或使用自定义参数:
this.gaService.triggerPageView('custom title', 'custom location', 'custom page');
Trigger event
从控制器触发事件:
this.gaService.triggerEvent('button', 'click');
或使用 gaEvent
指令从视图触发事件。 该指令向 GA 发送一个点击事件,其中元素的标记名作为类别,点击作为动作,内部文本作为标签,指令输入作为值。
没有价值
<button type="button" gaEvent>Switch gender to male with directive</button>
的触发事件:有价值的触发事件:
<button type="button" [gaEvent]="activeGender">Switch gender to male with directive</button>
Contributing
访问我们的贡献指南了解更多关于如何贡献的信息。
@acpaas-ui/ngx-analytics
This service adds an Angular layer on top of the Google Analytics ga()
function.
Usage
import { AnalyticsModule } from '@acpaas-ui/ngx-analytics';
Documentation
Visit our documentation site for full how-to docs and guidelines
Analytics service
Methods
Method | Description |
---|---|
setDimension(key: string, value: string) | Send a custom dimension. More info on dimensions and its parameters can be found in the Google Analytics documentation. |
triggerPageView(title?: string, location?: string, page?: string) | Trigger a page view with optional custom parameters. More info on page tracking and its parameters can be found in the Google Analytics documentation. |
triggerEvent(category: string, action: string, label?: string, value?: any) | Trigger an event with optional custom parameters. Usually the category is the tagname of the element. More info on event tracking and its parameters can be found in the Google Analytics documentation. |
Example
import { AnalyticsModule } from '@acpaas-ui/ngx-analytics';
@NgModule({
imports: [
AnalyticsModule
]
});
export class AppModule {};
By default there is a page trigger for each route change. To disable this feature for a specific route, add doNotTrack: true
to your route's data in app-routing.module.ts
.
{
path: 'home',
component: HomePage,
data: {
doNotTrack: true
}
}
import { GAService } from '@acpaas-ui/ngx-analytics';
constructor(
private gaService: GAService
) {}
Set dimension
this.gaService.setDimension('some-dimension', 'some-value');
Trigger page view
Use default parameters:
this.gaService.triggerPageView();
Or use custom parameters:
this.gaService.triggerPageView('custom title', 'custom location', 'custom page');
Trigger event
Trigger an event from the controller:
this.gaService.triggerEvent('button', 'click');
Or trigger an event from the view with the gaEvent
directive. This directive sends a click event to GA with the tagname of the element as category, click as action, the inner text as label and the directive input as value.
Trigger event without value:
<button type="button" gaEvent>Switch gender to male with directive</button>
Trigger event with value:
<button type="button" [gaEvent]="activeGender">Switch gender to male with directive</button>
Contributing
Visit our Contribution Guidelines for more information on how to contribute.