Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Settings User-Defined Setting in GoogleService-info.plist

I have the following GoogleService-info.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>TRACKING_ID</key>
    <string>$(GA_tracking_id)</string>
    <key>PLIST_VERSION</key>
    <string>1</string>
    <key>BUNDLE_ID</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</dict>
</plist>

Part of my build settings looks like this:

enter image description here

However when I log Google Analytics, the variable is not dereferencing:

VERBOSE: GoogleAnalytics 3.13 -[GAIBatchingDispatcher persist:] (GAIBatchingDispatcher.m:517): Saved hit: {
    parameters =     {
        "&av" = "1.0.0";
        "&dm" = "x86_64";
        "&ds" = app;
        "&sr" = 640x1136;
        "&t" = screenview;
        "&tid" = "$(GA_tracking_id)";
        "&ul" = "en-us";
        "&v" = 1;
        gaiVersion = "3.13";
    };
    timestamp = "2015-11-04 17:38:54 +0000";
}

I've used this strategy with Fabric, but that was in my Info.plist file. Also, the $(PRODUCT_BUNDLE_IDENTIFIER) works as expected. How do I get the variable to dereference instead of printing out it's literal string value.

like image 511
Mike V Avatar asked Nov 04 '15 17:11

Mike V


People also ask

What is GoogleService-info plist?

GoogleService-info plist file is one of a file that you can download when you use third party service such as Firebase. A lot of times, we might forget to download or we could have lost the file. There are a lot of ways to find GoogleService-info.

How do I get Xcode build settings?

Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.

How do I add a user defined variable in Xcode?

Select your project or target from the left side of the editor. Click the Build Settings button at the top of the editor. Click the Add Build Setting button at the bottom of the editor and choose Add User-Defined Setting.

Is GoogleService-info plist secret?

How do I secure this information from prying eyes? The API keys in the GoogleServices-info. plist are not secret information. They are just identifiers needed for your app to be able to find its Firebase back-end.


1 Answers

You can't use User-Defined settings in custom plist files, and that includes Google Analytics.

I've found a workaround in this other answer: https://stackoverflow.com/a/34070725/2192163 Basically, the trick is to create a run script that copies your custom plist version to the Google Analytics plist one.

like image 165
Lluis Gerard Avatar answered Oct 02 '22 03:10

Lluis Gerard