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?
The way that the Google plugin is set up, it will be really hard for you to hide the content of the google-services. json file. The only viable way would be to re-implement yourself what the plugin already does for you, which I wouldn't recommend.
Introduction. The google-services plugin has two main functions: Process the google-services. json file and produce Android resources that can be used in your application's code.
paste it into Project view -> app folder in your android-studio app. Suppose you are not able to do it, just do this. That json file referenced in android-studio cache so once close your android studio and then delete this file it will delete..
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With