简体   繁体   中英

How to add Google Analytics event label to Angulartics2?

In Angulartics2 , how do you pass the event label to Google Analytics?

Currently I have this code:

<a type="button" [routerLink]="['SecondPage']" angulartics2On="click" angularticsCategory="Click" angularticsEvent="Homepage">Click me</a>

When using the Analytics debugger for Chrome, it shows an event being fired which passes category and action. Looking at the code in GitHub makes it look like it is possible to supply a label, but I'm not clear what attribute needs adding to the anchor tag? angularticsLabel doesn't appear to have any effect.

Try to use the angularticsProperties parameter

angularticsProperties="{label: 'some label'}"

cf. https://github.com/angulartics/angulartics2/issues/22

另一个答案提供了正确的方法,但是由于代码中eval ,因此也有必要将Object文字用括号括起来

angularticsProperties="({label: 'some label'})"

The new version now (1.1.9) is:

[angularticsProperties]="{label: 'YourLabel'}"

I just udpated README file by a PR here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM