GTM for Mobile: Updating Your iOS Application Through Google Tag Manager


September 11, 2015

Google Tag Manager is traditionally used as a tool to control website tags. Analytics users mostly know it as a platform that enables them to control their analytics and advertising tags without the need to update their website or application. Did you know that you can use GTM for mobile as well? In this post I introduce a GTM functionality that lets you configure your iOS application without having to rebuild it.

Pushing updates for mobile from the Google Tag Manager is one of its most underused features. Using GTM for mobile has great potential when it comes to live updates and optimization. When using Google Tag Manager you can update your application in seconds without touching any of the source code. Good implementation of GTM will allow you live updates of many elements of the app such as:

  • Application Style (update colors, font sizes, element sizes etc.)
  • Text (using different wording, updating promotions etc.)
  • Configuration (changing required fields in a form)
  • Game level difficult (update the difficulty of your game’s level from GTM)
  • Hiding/displaying ads (with a simple 0/1 switch you can hide or display banners inside your app)

To demonstrate how to take advantage of the functionality I have created a simple one screen app that displays greetings text. I will update the text and the position of the text from Google Tag Manager without changing any code. You can use the exact same steps to configure this functionality on larger apps and update their content, settings, etc. once they have been installed on users’ phones or tablets.

Step 1: Create a GTM Container

To follow this tutorial you will first need to create a container in the Google Tag Manager. Head over to the https://tagmanager.google.com/ and follow the steps below:

  1. Create a new account.
  2. Setup the new account and container name.

Step 2: Creating a Collection Value Variable (Macro)

  1. From the left menu, select variables.
  2. Create a user defined variable.
  3. Choose a Value Collection type
  4. Configure the value as a json:
    {
      'greetings': 'Hello!',
      'greetings-alignment': 'left'
    }
    
  5. For now set the variable to be always enabled.
  6. Rename the variable to something that you will be able to find fast as your container grows.
  7. Create the variable.

Step 3: Installing GTM SDK

To use the functionality, your application will need to have Google Tag Manager implemented. The instructions on how to do that are available in Google Tag Manager documentation. Let me know in the comments or via Twitter if you encounter any problems with the installation. If it proves to be difficult for many of you, we will provide a step by step tutorial. The working code of the example used in this post is available on GitHub.

Step 4: Updating the App Code to Read Values From GTM

For my example I will be updating a greeting text in my app. Inside my view controller the text is accessible through the UILabel called greetingsText.

  1. First we’ll need to reference the container that we’ve set up in the app delegate.
       AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
       TAGContainer *container = appDelegate.container;
    
  2. Using stringForKey method of the container, we’ll reference the key greetings from the value collection variable in our GTM container and update the text of the current greetingsText UILabel.
       self.greetingsText.text = [container stringForKey:(@"greetings")];
  3. As a final step we retrieve the alignment and update the text alignment accordingly.
       NSString *alignment = [container stringForKey:(@"greetings-alignment")];
       if ( [alignment isEqualToString:@"left"])
          self.greetingsText.textAlignment = NSTextAlignmentLeft;
       else if([alignment isEqualToString:@"right"])
          self.greetingsText.textAlignment = NSTextAlignmentRight;
       else
          self.greetingsText.textAlignment = NSTextAlignmentCenter;
    

Step 5: Update Your App From GTM

All you need to do now to change your application’s greetings text to “Howdy!” is update the value collection variable in your Google Tag Manager and publish the new container version.

Updating text to right alignment and “Hello!” from Google Tag Manager.

 

Updating text to left alignment and “Howdy!” from Google Tag Manager. Updating text to left alignment and “Howdy!” from Google Tag Manager.

There you have it! Again, if you have any questions or comments, let us know! Yet to come: Learn how to update an Android app from GTM.

*The App example code is available on GitHub.