简体   繁体   English

angulartics2 自定义事件发送到 facebook 但不发送到谷歌分析

[英]angulartics2 custom events are sent to facebook but not to google analytics

I use angulartics2 with an angular7 project to fire events to facebook and google analytics.我将 angulartics2 与 angular7 项目一起使用,以将事件触发到 facebook 和 google 分析。

I have facebook and google analytics configured using google tag manager.我使用谷歌标签管理器配置了 Facebook 和谷歌分析。

the problem is my custom events are fired and sent to facebook but not to google analytics.问题是我的自定义事件被触发并发送到 facebook 而不是 google 分析。

below the <head> tag I have the google tag manager code.<head>标签下方,我有谷歌标签管理器代码。

in the main component typescript file I added the following code:在主要组件打字稿文件中,我添加了以下代码:

constructor(
  private angulartics2GoogleTagManager: Angulartics2GoogleTagManager,
  private angulartics2Facebook: Angulartics2Facebook,
  private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics
            ) {
    this.angulartics2Facebook.startTracking();
    this.angulartics2GoogleTagManager.startTracking();
    this.angulartics2GoogleAnalytics.startTracking();
...

for example when people add items to cart I want to fire an event about it.例如,当人们将商品添加到购物车时,我想触发一个关于它的事件。

so in my cart service I inject angulartics2 in the constructor:所以在我的购物车服务中,我在构造函数中注入了 angulartics2:

 constructor(@Inject(LOCAL_STORAGE) private storage: StorageService,
                private angulartics2: Angulartics2
                ) 

and then where it's relevant I fire the event with the following code:然后在相关的地方我用以下代码触发事件:

    this.angulartics2.eventTrack.next({action: 'addToCart', properties: {category: 'Cart', label: keyName, value: quantity}});

using facebook pixel chrome extension I can see that the custom event is detected, using google events chrome extension I can see that no event is detected.使用 facebook pixel chrome 扩展我可以看到检测到自定义事件,使用 google events chrome 扩展我可以看到没有检测到任何事件。

what am I missing?我错过了什么? what I didn't configure properly?我没有正确配置?

google analytics is configured properly in google tag manager, I do see users count and page views count properly.谷歌分析在谷歌标签管理器中配置正确,我确实看到用户计数和页面浏览量正确计数。

any information regarding this issue would be greatly appreciated.任何有关此问题的信息将不胜感激。

thanks谢谢

update更新

some more investigation information thanks to @XTOTHEL.感谢@XTOTHEL,提供更多调查信息。

so in the app.component.ts constructor I only enabled google tag manager to start tracking.所以在app.component.ts构造函数中我只启用了谷歌标签管理器来开始跟踪。

unfortunately google tag manager is not detecting any events being fired.不幸的是,谷歌标签管理器没有检测到任何被触发的事件。

attached a screenshot of google tag manager console after adding stuff to the cart and the angulartics2 code of adding addToCart custom event being fired.在向购物车添加东西后附上谷歌标签管理器控制台的屏幕截图,以及添加addToCart自定义事件的 angulartics2 代码被触发。

在此处输入图片说明

update 2更新 2

用于交互 addToCart 的标签选项卡

用于交互 AddToCart 的数据层选项卡

I don't know if this is what you are looking for, but I got some GTM events with pushLayer method from Angulartics2GoogleTagManager, from within a Service which extends on Angulartics2GoogleTagManager:我不知道这是否是您要查找的内容,但是我从 Angulartics2GoogleTagManager 的 pushLayer 方法中获得了一些 GTM 事件,该事件来自在 Angulartics2GoogleTagManager 上扩展的服务:

@Injectable()
export class GoogleTagManagerService extends Angulartics2GoogleTagManager {

  public gtmProperties: GoogleTagManagerProperties = new GoogleTagManagerProperties();

  pageTrack(path: string) {
    if (typeof dataLayer !== 'undefined' && dataLayer) {
      dataLayer.push({
        event: 'pageView',
        action: path,
        'content-name': path,
        userId: this.angulartics2.settings.gtm.userId,
        ...this.gtmProperties
      });
    }
    return true;
  }

  setSearchCriteria(type: string, criteria) {
    this.pushLayer(type.toLowerCase().indexOf('listings') > -1 ?
      {
        event: 'search',
        action: type,
        'content-name': type,
        userId: this.angulartics2.settings.gtm.userId,
        searchCriteriaListings: criteria
      } : {
        event: 'search',
        action: type,
        'content-name': type,
        userId: this.angulartics2.settings.gtm.userId,
        searchCriteriaPostings: criteria
      });
  }

}

which would bring me a new dataLayer with information like this:这会给我带来一个新的 dataLayer,其中包含如下信息: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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