autoActivityTracking while using google

I read about usage of google-services.json in What does google-services.json really do? : After releasing your app in public, it will not work without the json file.

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
mTracker = analytics.newTracker(R.xml.global_tracker);

I read in another article about autoActivityTracking . We can also create a xml resource file under res/xml/ and setup Activities we want to track:

        <string name="ga_trackingId">UA-XXXXXX-X</string>

        <bool name="ga_autoActivityTracking">true</bool>

        <screenName name="com.example.android.dinnerapp.MainActivity">
            Main screen
        </screenName>

        <screenName name="com.example.android.dinnerapp.OrderDinnerActivity">
            Order dinner
        </screenName>

        <screenName name="com.example.android.dinnerapp.RemoveMealActivity">
            Eradicate dinner
        </screenName>

        <screenName name="com.example.android.dinnerapp.ShowDinnerActivity">
            Show dinner
        </screenName>

        <screenName name="com.example.android.dinnerapp.ShowRecipeActivity">
            Show recipe
        </screenName>

And set it up by using :

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
mTracker = analytics.newTracker(R.xml.track_app);

I wonder how it is possible when we are using json file instead?


I've stumbled upon the very same problem right now, did a little investigation and came to a conclusion that this can't be done .

Judging by the sources of the Gradle plugin which generates resources from google-services.json , all it can put in the configuration XML file is the tracking id. Here's the relevant part of code:

private static String getGlobalTrackerContent(String ga_trackingId) {
    return "<?xml version="1.0" encoding="utf-8"?>n" +
            "<resources>n" +
            "    <string name="ga_trackingId">" + ga_trackingId + "</string>n" +
            "</resources>n";
}

Since you can't split the configuration file in two, I don't see a way to use these properties and the plugin at the same time.

I would say you should just generate the files once, put them into your resources, then remove the plugin and add whatever strings you need yourself. I'm disappointed myself that Google removes old instructions and puts out new ones which involve using some half-baked solutions.

链接地址: http://www.djcxy.com/p/30326.html

上一篇: iOS键盘扩展中的多个键盘布局

下一篇: autoActivityTracking,同时使用谷歌