Making the Most Of Google Tag Manager for iOS

The release of Google Tag Manager (GTM) for iOS was great news for app developers. Now, developers can create updates for their user base without needing to publish new versions of the app. This is huge — before GTM for mobile, it was impossible to make any changes to your app without sending updates that users had to accept. With GTM, however, app developers can constantly make configuration through the GTM interface.

In addition to this feature, there are many other benefits and ways to use GTM for iOS.making-the-most-1Benefits of GTM for iOS

Manage configuration values

There are several types of configuration values and flags you may want to change in your app, including UI settings and display strings, sizes, locations, types of ads, and settings.

Evaluate configuration values

With GTM, you can evaluate values at runtime using rules. This enables you to access dynamic configurations, such as using screen size to determine optimal ad banner dimensions and using language or location to configure UI elements.

Dynamic implementation

You can use GTM for dynamic implementation of tracking tags and pixels. With Google Mobile App Analytics and Custom Function Call tag (the two tags supported by GTM), you can push important events into the DataLayer. The DataLayer is a map that allows you to send runtime information about your app to Tag Manager macros and tags in a container. Later, this information will determine the appropriate tracking tags and pixels to fire.

Examples of How to Use GTM for iOS

Add Google Tag Manager SDK

To include GTM SDK in your project, you need to add several files. To begin, include libGoogleAnalyticsServices.a and all the GTM header files from the Library directory of your SDK package.

Next, check that you have all the linked libraries of your app target. You should have CoreData.framework, SystemConfiguration.framework, libz.dylib, libsqlite3.dylib, and libGoogleAnalyticsServices.a.

Finally, you if you want your app to access identifier for advertisers (IDFA) and tracking flag provider by that framework through GTM SDK macros, you will also need to link libAdIdAccess.a and AdSupport.framework.

Custom refresh period

Every 12 hours, GTM SDK will attempt to retrieve a fresh container. You can customize this setting to your own container refresher period with NSTimer. The code looks like this:

(void)refreshContainer:(NSTimer *)timer {

[self.container refresh];

}

self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:<refresh_interval>

target:self

selector:@selector(refreshContainer:)

userInfo:nil

repeats:YES];

Default containers

Default containers are necessary if you want your users to be able to retrieve tags and configurations from the network when they are not connected to the Internet. This will ensure that at least one container version is always available to the app, which users can access until they are able to retrieve another container from the network.

To add a default container, sign in to GTM web interface and choose a version of the container to download. Add it to the root directory of your project along with the Supporting Files folder. Name the file according to the container ID, removing the suffix.

Evaluate macrosmaking-the-most-2

Using Rules, you can evaluate macros at runtime. Choose criteria for rules, such as device language, platform, or another macro value. By publishing the container, the app will display localized display strings according to the macro value.

 

If you like my articles,