【问题标题】:Track WCF REST using GoogleAnalyticsTracker使用 GoogleAnalyticsTracker 跟踪 WCF REST
【发布时间】:2012-11-07 10:28:43
【问题描述】:

我在http://myapp.cloudapp.net/Service1.svc 有一个安静的 WCF,它返回 json 数据。 wcf 现在在 Azure 中。 我想使用 googleAnalyticsTracker 跟踪 WCf 的使用情况。通过向其发送 http 请求来使用我的 WCf 的所有客户端,我希望它们被 googleAnalytics 跟踪。

我在 googleAnalytics 创建了一个帐户,并提供了与上述相同的 URL 以供跟踪服务。

Service1.svc 中唯一的操作 GetData() 会在浏览 http.../Service1.svc 时调用,GetData() 中的 Trakcer 代码如下:

Tracker tracker = new Tracker("UA-xxxxx-x", "http://myapp.cloudapp.net/");

        //var request = svcSecurityContext;
        tracker.SetCustomVariable(1, "Time", DateTime.Now.ToShortDateString());
        tracker.SetCustomVariable(2, "UserName", "myname");

        tracker.SetCustomVariable(3, "Service accessed",     OperationContext.Current.RequestContext.RequestMessage.Headers.To.ToString());

        tracker.TrackPageView("My API - Create", "api/create");

服务返回数据,然后我转到 googleAnalytics 的 mydashboard,我看不到访问量正在增加。我需要帮助来确定我是否正确使用了 googleanalytictracker。

是否可以像 iam 那样使用带有 wcf 的 googleanalytics,或者它只能用于网页?

谢谢

【问题讨论】:

    标签: wcf rest google-analytics


    【解决方案1】:

    您查看过 Google Analytics(分析)跟踪器吗? https://github.com/maartenba/GoogleAnalyticsTracker

    该代码适用于 ASP.NET Web API,但也可用于 WCF。对于 WCF,我将使用此代码创建一个行为。

    【讨论】:

    • 是的,巴特。我正在使用与 GoogleAnalytics 链接中相同的代码,但它不起作用,在我的谷歌帐户中没有跟踪任何内容。我想更多地了解您对行为的看法。您的意思是我可以创建一种行为来使 googleAnalytics 工作吗?我不知道该怎么做,但如果你能提供链接、教程或代码,我将非常感激。
    【解决方案2】:

    它可以工作,但 GoogleAnalytics 不显示统计信息,因为获取更新的统计信息需要一些时间。对我来说大约需要1个小时。 此链接显示您如何简单地显示今天的统计数据:

    real-time-stats-with-google-analytics

    【讨论】:

      【解决方案3】:

      效果很好,但我在 Google Analytics 中看不到我的自定义变量!

              using (Tracker tracker = new Tracker("UA-xxxxx-x", "http://myapp.cloudapp.net/"))
              {                
                  tracker.SetCustomVariable(1, "User id", uid);
                  tracker.SetCustomVariable(2, "Test", "ok");
                  tracker.SetCustomVariable(3, "Test2", "fgd");
                  tracker.SetCustomVariable(4, "Test3", "PPP");
                  tracker.SetCustomVariable(5, "Test4", "dfsPPP");
      
                  tracker.TrackPageView("PortecarteService", "ws/GetListFolder");
              }
      

      谢谢

      【讨论】:

        猜你喜欢
        • 2012-06-16
        • 2013-09-15
        • 2011-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-05
        相关资源
        最近更新 更多