简体   繁体   English

如何在我的Angular 4应用程序中使用angulartics2(Adobe Analytics)跟踪事件

[英]How to track events with angulartics2 (Adobe Analytics) in my Angular 4 application

I am trying to track my page views in my Angular 4 application, specifically using Adobe Analytics. 我试图在我的Angular 4应用程序中跟踪我的页面视图,特别是使用Adobe Analytics。

I am using angulartics2. 我正在使用angulartics2。

To start I added the necessary adobe staging script in my index.html page 首先,我在index.html页面中添加了必要的adobe staging脚本

 <script src="//assets.adobedtm.com/ab4bae3236ee9df67d8ccdffde34299268b1c40b/satelliteLib-760b49f02b6b0eb2f709fccf152b67359e5ee4e1-staging.js"></script>

I then enable the providers in my NgModule. 然后我在我的NgModule中启用提供程序。

import { Angulartics2Module, Angulartics2AdobeAnalytics } from 'angulartics2';

@NgModule({
 declarations: [
AppComponent
],
 imports: [

   Angulartics2Module.forRoot([Angulartics2AdobeAnalytics]),
 ],
 providers: [],
 bootstrap: [AppComponent]
   })
 export class AppModule { }

I then import the provider in my root component. 然后我在我的根组件中导入提供程序。

import { Angulartics2AdobeAnalytics } from 'angulartics2';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
 export class AppComponent implements OnInit {


 constructor(private angulartics2AdobeAnalytics:Angulartics2AdobeAnalytics){} 

I attempt to track events in the code of my component (dashboard for example) but the values are not pulling through. 我试图在我的组件的代码中跟踪事件(例如仪表板),但值不是通过。

import { Angulartics2 } from 'angulartics2';

 constructor(
    private angulartics2: Angulartics2
  ) {   
        this.angulartics2.eventTrack.next({
          properties: {
            "siteLanguage": "English",
            "pageCategory": "Landing dashboard",
            "pageSubSection1": "",
            "pageSubSection3": "",
            "domainName": "www.application.co.za",
            "pageSubSection2": "",
            "pageSubSection5": "",
            "pageSubSection4": "",
            "pageName": "Landing dashboard",
            "contentType": "Home"
          },
        });
  }

Any suggestions perhaps on how to do this so that it works? 有关如何做到这一点的任何建议,以便它的工作?

Explicitly adding this to my index file does work though this is not a solution. 将此明确添加到我的索引文件确实有效,尽管这不是解决方案。

<script>
    var dataLayer = {
      "siteLanguage": "English",
            "pageCategory": "Landing dashboard",
            "pageSubSection1": "",
            "pageSubSection3": "",
            "domainName": "www.application.co.za",
            "pageSubSection2": "",
            "pageSubSection5": "",
            "pageSubSection4": "",
            "pageName": "Landing dashboard",
            "contentType": "Home"
       };
     </script>

Kind regards 亲切的问候

I know a little angular2, and I know Adobe Analytics very well, but I'm not familiar with angulartics, but I'll see if I can be helpful. 我知道一点角度2,我非常了解Adobe Analytics,但我不熟悉angulartics,但我会看看我是否能提供帮助。 Any time an adobe analytics implementation isn't working, it's going to be at least one of three things: 任何时候adobe分析实现都不起作用,它将至少是三件事之一:

  1. AppMeasurement and the "s" object (typically held in an "s_code.js" file, or built automatically by DTM for a fully-DTM-implementation) aren't set up correctly, or aren't accessible. AppMeasurement和“s”对象(通常保存在“s_code.js”文件中,或由DTM自动构建,用于完全DTM实现)未正确设置或无法访问。
  2. Variables like s.pageName or custom variables like s.eVar1 aren't getting set correctly (though this shouldn't stop a variable from being set altogether. 像s.pageName这样的变量或者像s.eVar1这样的自定义变量没有正确设置(尽管这不应该阻止变量完全设置)。
  3. You aren't firing st (to track a page view) or s.tl (for things you want to track that shoudn't be associated with a specific page view) at the right time. 您没有在正确的时间触发st(跟踪页面视图)或s.tl(对于您要跟踪的事物,而不是与特定页面视图关联)。

I can see how Angulartics2AdobeAnalytics accomplishes #2 (it does pageName automatically, and you would use setUserProperties for custom variables) and how it accomplishes #3 (pageTrack and eventTrack). 我可以看到Angulartics2AdobeAnalytics如何完成#2(它会自动执行pageName,你会使用setUserProperties来实现自定义变量)以及它如何完成#3(pageTrack和eventTrack)。 I'm not sure how it wants you to set up that s oject or host an s_code. 我不确定它是如何设置该项目或托管s_code的。

It does look like angulartics is intended to be used instead of DTM, not alongside it like you are trying (angulartics is like a mini tag management system itself). 看起来像是用来代替 DTM的angulartics, 而不是像你正在尝试的那样(angulartics就像一个迷你标签管理系统本身)。 I don't imagine DTM is doing anything that would help Angulartics. 我不认为DTM正在做任何有助于Angulartics的事情。 What I can't figure out from the Angulartics2AdobeAnalytics documentation is where you SHOULD be putting your s_code. 从Angulartics2AdobeAnalytics文档中我无法弄清楚的是你应该把你的s_code放在哪里。 DTM does create an Adobe Analytics Library/s_code file (for instance, yours is kept at http://assets.adobedtm.com/ab4bae3236ee9df67d8ccdffde34299268b1c40b/s-code-contents-d284ea5dda8dda4834d869c1d6edac2867ea95ac-staging.js ), but it is scoped to only be accessible within DTM, so it wouldn't be helping in your current set up at all (see https://www.digitaldatatactics.com/index.php/2016/01/15/how-to-get-a-global-s-object-in-dtm/ for how to get DTM to create an s_code that can be used globally). DTM会创建一个Adobe Analytics Library / s_code文件(例如,您的文件保存在http://assets.adobedtm.com/ab4bae3236ee9df67d8ccdffde34299268b1c40b/s-code-contents-d284ea5dda8dda4834d869c1d6edac2867ea95ac-staging.js ),但它的范围仅限于可以在DTM中访问,因此它根本不会对您当前的设置有所帮助(请参阅https://www.digitaldatatactics.com/index.php/2016/01/15/how-to-get-a-global- s-object-in-dtm /如何让DTM创建一个可以全局使用的s_code。
It might be you need to remove DTM from your solution and just figure out how Angulartics wants that "s" object stuff set up. 您可能需要从解决方案中删除DTM,并弄清楚Angulartics如何设置“s”对象。 Maybe you just need to put an s_code file in place of your DTM library (see https://marketing.adobe.com/resources/help/en_US/sc/implement/impl_js_file.html which IS referenced from https://github.com/angulartics/angulartics2/tree/master/src/lib/providers/adobeanalytics which makes me think they intend you to use it), then you wouldn't need to get DTM to play nicely with Angulartics. 也许你只需要用一个s_code文件代替你的DTM库(参见https://marketing.adobe.com/resources/help/en_US/sc/implement/impl_js_file.html ,它是从https:// github引用的。 com / angulartics / angulartics2 / tree / master / src / lib / providers / adobeanalytics ,这让我觉得他们打算你使用它),那么你就不需要让DTM与Angulartics很好地玩了。

If you want to go the strictly-DTM (not Angulartics) route, I have gotten that working in an Angular app- it's at https://github.com/jkunz/pocketSDR/tree/master/src but please don't judge my angular skills- this was a learning project:) I added my DTM library embed code to my index.html (just like you have), then interacted directly with DTM's js object (_satellite) throughout the app to set DTM Data Elements (with values for my variables- see point #2) and trigger DTM Direct Call Rules to fire beacons at the right time (point #3). 如果你想要严格的DTM(不是Angulartics)路线,我已经在Angular应用程序中工作了,请访问https://github.com/jkunz/pocketSDR/tree/master/src,但请不要判断我的角度技能 - 这是一个学习项目:)我将我的DTM库嵌入代码添加到我的index.html(就像你有),然后直接与整个应用程序中的DTM的js对象(_satellite)进行交互以设置DTM数据元素(与我的变量的值 - 参见第2点)并触发DTM直接呼叫规则以在正确的时间(第3点)发射信标。 If I hadn't cared about setting custom variables and truly just wanted to leave it to bare minimum page view tracking every time the view changed, I could have put the DTM library on my index.html, then just set an event-based rule that looked for something like locationchange ( https://www.digitaldatatactics.com/index.php/2016/04/20/how-do-i-use-dtm-for-a-single-page-app/ has info on that). 如果我不关心设置自定义变量,并且真的只是想在每次视图更改时将其留给最小的页面视图跟踪,我可以将DTM库放在我的index.html上,然后只需设置基于事件的规则寻找像locationchange这样的东西( https://www.digitaldatatactics.com/index.php/2016/04/20/how-do-i-use-dtm-for-a-single-page-app/有关于那)。

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

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