Xamarin google Play服务组件分析trackEvent不起作用

时间:2015-01-16 13:49:12

标签: google-analytics xamarin xamarin.android

我正在使用捆绑在" Google Play服务中的Google Analytics" Xamarin中的组件,但我的Track事件不起作用。谁知道为什么?

private Tracker getTracker()
    {
         var googleAnalyticsInstance = GoogleAnalytics.GetInstance(((AndroidAppFeatures)App.AppFeatures).Activity.BaseContext);

        var tracker = googleAnalyticsInstance.NewTracker("UA-58482516-1");
        return tracker;

    }
    public  void TrackPageView(Xamarin.Forms.ContentPage viewModel)
    {
        var tracker = getTracker();
        tracker.SetScreenName(GetViewName(viewModel));
        var screenViewBuilder = new HitBuilders.ScreenViewBuilder();
        tracker.Send(screenViewBuilder.Build());
    }

    public void TrackEvent(string category, string action, string label, long value = 0)
    {
        var tracker = getTracker();
        tracker.Send(new HitBuilders.EventBuilder().SetCategory(category).SetAction(action).SetLabel(label).SetValue(value).Build());
        tracker.Send(new HitBuilders.ScreenViewBuilder().Build());
    }

1 个答案:

答案 0 :(得分:1)

出于某种原因,它对我也没有用。在我将配置添加为xml后,它工作正常:

<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">

    <!--Replace placeholder ID with your tracking ID-->
    <string name="ga_trackingId">UA-xxxxxxxxx</string>

    <!--Enable automatic exception tracking-->
    <bool name="ga_reportUncaughtExceptions">true</bool>

    <!--Enable automatic activity tracking-->
    <bool name="ga_autoActivityTracking">true</bool>

    <bool name="ga_dryRun">false</bool>

    <string name="ga_logLevel">info</string>

    <integer name="ga_dispatchPeriod">30</integer>

</resources>