简体   繁体   中英

Angularitics (GA) add fixed value to all tracked events

I am using Angularitics (GA analytics) in my app.

Here's what I doing in my jade file. a.btn(href="www.some.com" analytics-on="click" analytics-label={{UserID}} analytics-category="Some Category" analytics-event="Some Event")

Now I have a ton of these and the label is always UserId so i can track events by user.

Is there a simpler way to add a constant across the board value to all events. I have an angular app and want to add the userID for the logged in user to all events i track. Looking for a way to add that info without having to add it to each element i track in the html.

I would just recommend you using GTM instead.

With Angulartics and GTM, you can access the dataLayer directly with

window.dataLayer

So you can do something like this at the start of you controller or main app.

window.dataLayer.push('userId','example123');

Then in GTM just read that into a variable and push into GA with the userId as label for the event.

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