Skip to content

Instantly share code, notes, and snippets.

@object2dot0
Created December 1, 2015 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save object2dot0/539310b0ca113b4c367b to your computer and use it in GitHub Desktop.
Save object2dot0/539310b0ca113b4c367b to your computer and use it in GitHub Desktop.
#!/bin/sh
# Setup_GoogleAnalytics_API_Keys.sh
# iOSConsumerApp
#
# Created by Muhammad Tanveer on 9/17/15.
# Copyright (c) 2015 iCarAsia. All rights reserved.
path_to_GoogleAnalytics_info_plist_file="$TARGET_BUILD_DIR/${PRODUCT_NAME}.app/GoogleService-Info.plist"
# Import keys and secrets from a file
. ${PROJECT_DIR}/GoogleAnalyticsAutomationScripts/GoogleAnalytics_keys.sh
if [ ${CONFIGURATION} = "AppStore" ]; then
echo "Release Build Configuration - Set GoogleAnalytics API Key to Production Organization"
the_current_gooleanalytics_api_key=`/usr/libexec/PlistBuddy -c "Print :TRACKING_ID" "$path_to_GoogleAnalytics_info_plist_file"`
echo "Current GoogleAnalytics API Key from GoogleService-Info: $the_current_gooleanalytics_api_key"
echo "GoogleAnalytics Production API Key: $the_googleanalytics_production_api_key"
if [ "$the_current_gooleanalytics_api_key" == "$the_googleanalytics_production_api_key" ]
then
# Keys match - do not change
echo "GoogleAnalytics API Keys match. Will not update"
else
# Keys do not match - will change
echo "Current GoogleAnalytics API Key is not the same as new API Key, will change"
/usr/libexec/PlistBuddy -x -c "Set :TRACKING_ID $the_googleanalytics_production_api_key" "$path_to_GoogleAnalytics_info_plist_file"
the_updated_gooleanalytics_api_key=`/usr/libexec/PlistBuddy -c "Print :TRACKING_ID" "$path_to_GoogleAnalytics_info_plist_file"`
echo "GoogleAnalytics API Key set to: $the_updated_gooleanalytics_api_key"
fi
else
echo "AdHoc OR Debug Build Configuration - Set GoogleAnalytics API Key to Development Organization"
the_current_gooleanalytics_api_key=`/usr/libexec/PlistBuddy -c "Print :TRACKING_ID" "$path_to_GoogleAnalytics_info_plist_file"`
echo "Current GoogleAnalytics API Key from GoogleService-Info: $the_current_gooleanalytics_api_key"
echo "GoogleAnalytics Development API Key: $the_googleanalytics_development_api_key"
if [ "$the_current_crashlytics_api_key" == "$the_googleanalytics_development_api_key" ]
then
# Keys match - do not change
echo "GoogleAnalytics API Keys match. Will not update"
else
# Keys do not match - will change
echo "Current GoogleAnalytics API Key is not the same as new API Key, will change"
/usr/libexec/PlistBuddy -x -c "Set :TRACKING_ID $the_googleanalytics_development_api_key" "$path_to_GoogleAnalytics_info_plist_file"
the_updated_gooleanalytics_api_key=`/usr/libexec/PlistBuddy -c "Print :TRACKING_ID" "$path_to_GoogleAnalytics_info_plist_file"`
echo "GoogleAnalytics API Key set to: $the_updated_gooleanalytics_api_key"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment