TagManager, what's that? Actually that's a pretty fair question.
Google hasn't done a great job of explaining what TagManager is, why you care and how to use it very well, especially for Android. This is probably because TagManager has come from the world of web marketing and has really only recently received some Android love.But now that TagManager is part of Google Play Services (and if you aren't using Google Play Services yet you should really be asking why you aren't) integrating it into your app is a breeze.
Firstly: What is it and why should you use it?
I won't dig into the full details of TagManager, I'll let you explorer those later. Where I think you'll get most value out of TagManager initially is by using it to specify app config values for which you might want to push out new values to all your users. Eg I only show interstitial ads after 20% of games played in one of my apps. But maybe I want to be able to play with that after I have shipped. TagManager will let me do that by updating the config in its web interface and publishing a new version of the TagManager Container.How to integrate TagManager
You'll need to sign up for TagManager (etc), create a Container and for app config variables create a MACRO of type value-collection. Start here https://developers.google.com/tag-manager/android/v4/Don't worry too much about the weird names that TagManager uses (MACRO etc). There is a revamp due to be rolled out Jan 2015 that brings a nicer UI and names that are a lot clearer.
Once you have created and downloaded your TagManager Container to res/raw (heads up - the default name for the Container file does not follow Android resource naming conventions and you will have to change it), you can start adding code.
Start with your Application class and add the following:
// Make sure we always have a TagContainer instance private TagContainer tagContainer = new TagContainer(null); public TagContainer getTagContainer() { return tagContainer; } // Call this from Application#onCreate private void configureTagManager() { final TagManager tagManager = TagManager.getInstance(this); final PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault(GTM_CONTAINER_ID, R.raw.gtm_mycontainer_v5); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Override public void onResult(ContainerHolder containerHolder) { tagContainer = new TagContainer(containerHolder); if (containerHolder.getStatus().isSuccess()) { Log.i(TAG, "GTM container loaded"); } else { Log.w(TAG, "Failure loading GTM container : " + containerHolder.getStatus().getStatusMessage()); } } }); }
We introduced the TagContainer class here to make our life simple. It looks like:
public class TagContainer { private static final String SHOW_FULL_SCREEN_AD_PERCENTAGE = "showFullScreenAdPercentage"; private final ContainerHolder containerHolder; public TagContainer(ContainerHolder containerHolder) { this.containerHolder = containerHolder; } /** * Defaults to 0.20 */ public double showFullScreenAdPercentage() { final Container container = getContainer(); return container == null ? 0.20 : container.getDouble(SHOW_FULL_SCREEN_AD_PERCENTAGE); } private Container getContainer() { return containerHolder == null ? null : containerHolder.getContainer(); } }And finally add it into the code where you want to use the value:
if (coinToss < getTagContainer().showFullScreenAdPercentage()) { // show interstitial }
Voila, instant app config.
The End Game
So now you can ramp the ad percentage up or down without needing to release a new version of your app. Just update the TagManager web interface, publish the new version of the Container and within 12 hours it will ave rolled out to all your users.So for those of you who have been managed your own server and transport for app config, here's your chance to cut down on the code you need to manage.
And now that you have that ability, what else do you want to be able to tweak in your app after deployment?