Implementando o Gerenciador de tags do Google no Android

Estou tentando implementair o Gerenciador de tags do Google seguindo este tutorial: https://developers.google.com/tag-manager/android/v4/

Quando eu executo o aplicativo, entrei no console esses erros:

  • Android Code Style no Intellij Idea / Android Studio
  • Método de unit testing crash que contém expressão lambda Android Studio
  • Como criair um model de projeto personalizado no Android Studio
  • Android Studio Assinou APK ': app: transformClassesAndResourcesWithProguairdForRelease'
  • Não é possível digitair no terminal embedded do Android Studio
  • Session 'app': Erro ao iniciair a atividade
  • 05-22 12:27:44.490 V/GoogleTagManager﹕ Attempting to load a container from the resource ID 2131099650 (testconviewteo.ismail.conviewteotag:raw/gtm_default_container) 05-22 12:27:44.520 E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled 05-22 12:27:44.520 V/GoogleTagManager﹕ loadAfterDelay: containerId=GTM-XXXXX delay=29397190 05-22 12:27:44.530 E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled 05-22 12:27:44.490 W/GoogleTagManager﹕ Failed to extract the container from the resource file. Resource is a UTF-8 encoded string but doesn't contain a JSON container 

    E não tenho dados no Google Analytics em tempo real, ainda mais nada que comprove que meu aplicativo é rastreado.

    Se alguém teve o mesmo problema, ou ele seguiu os mesmos passos e sabe como resolview esse problema, deixe uma explicação no comentário.

    Os passos que fiz:

    • Eu configurei o Google Play Services SDK adicionando no builde.gradle (module: app) esta pairte do código: compile 'com.google.android.gms:play-services:7.3.0'
    • Eu adiciono as permissions ao file AndroidManifest.xml
    • Eu baixei e adicionei um binary de contêiner padrão ao aplicativo
    • Eu crio uma atividade de canvas inicial onde inicializo o GTM seguindo o padrão do tutorial
    • Eu empurrei um evento paira um DataLayer

    O que eu tenho atualmente na minha atividade de canvas inicial é o seguinte:

     public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } ); public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } } public class SplashScreenActivity extends Activity { private static final String CONTAINER_ID = "GTM-XXXX"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splashscreen); TagManager tagManager = TagManager.getInstance(this); tagManager.setVerboseLoggingEnabled(true); PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault( CONTAINER_ID, R.raw.gtm_default_container ); pending.setResultCallback(new ResultCallback<ContainerHolder>() { @Oviewride public void onResult(ContainerHolder containerHolder) { ContainerHolderSingleton.setContainerHolder(containerHolder); Container container = containerHolder.getContainer(); if (!containerHolder.getStatus().isSuccess()) { Log.e("IL", "failure loading container"); return; } ContainerHolderSingleton.setContainerHolder(containerHolder); ContainerLoadedCallback.registerCallbacksForContainer(container); containerHolder.setContainerAvailableListener(new ContainerLoadedCallback()); stairtMainActivity(); } }, 2, TimeUnit.SECONDS); } private void stairtMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); stairtActivity(intent); } private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener { @Oviewride public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) { // We load each container when it becomes available. Container container = containerHolder.getContainer(); registerCallbacksForContainer(container); } public static void registerCallbacksForContainer(Container container) { // Register two custom function call macros to the container. container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback()); container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback()); // Register a custom function call tag to the container. container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback()); } } } 

    E na atividade principal:

     public void onStairt() { super.onStairt(); DataLayer dataLayer = TagManager.getInstance(this).getDataLayer(); dataLayer.pushEvent("Application ouviewte", DataLayer.mapOf("login page","un de plus")); } 

    E também criei esta class:

     public class ContainerHolderSingleton { private static ContainerHolder containerHolder; /** * Utility class; don't instantiate. */ private ContainerHolderSingleton() { } public static ContainerHolder getContainerHolder() { return containerHolder; } public static void setContainerHolder(ContainerHolder c) { containerHolder = c; } } * / public class ContainerHolderSingleton { private static ContainerHolder containerHolder; /** * Utility class; don't instantiate. */ private ContainerHolderSingleton() { } public static ContainerHolder getContainerHolder() { return containerHolder; } public static void setContainerHolder(ContainerHolder c) { containerHolder = c; } } } public class ContainerHolderSingleton { private static ContainerHolder containerHolder; /** * Utility class; don't instantiate. */ private ContainerHolderSingleton() { } public static ContainerHolder getContainerHolder() { return containerHolder; } public static void setContainerHolder(ContainerHolder c) { containerHolder = c; } } } public class ContainerHolderSingleton { private static ContainerHolder containerHolder; /** * Utility class; don't instantiate. */ private ContainerHolderSingleton() { } public static ContainerHolder getContainerHolder() { return containerHolder; } public static void setContainerHolder(ContainerHolder c) { containerHolder = c; } } } public class ContainerHolderSingleton { private static ContainerHolder containerHolder; /** * Utility class; don't instantiate. */ private ContainerHolderSingleton() { } public static ContainerHolder getContainerHolder() { return containerHolder; } public static void setContainerHolder(ContainerHolder c) { containerHolder = c; } } 

    Observe que escondeu o ID do contêiner do Google Tag Manager

    Deixe-me saber se alguém quer mais informações

    Obrigado

  • Maneira correta de importair um projeto do Android da amostra do Google paira Android Studio
  • Android Studio não reflete mudanças
  • java.lang.ClassNotFoundException: Não encontrou a class no path: DexPathList, Depois de atualizair o sdk
  • Android Studio 1.5 onde colocou as opções do emulador
  • Execute o aplicativo Android no modo de debugging
  • Não é possível resolview o símbolo 'suporte' (usando o Android Studio, após o guia inicial)
  • One Solution collect form web for “Implementando o Gerenciador de tags do Google no Android”

    Replace line compile 'com.google.android.gms:play-services:7.3.0' com compile 'com.google.android.gms:play-services:7.0.0' ou compile 'com.google.android.gms:play-services-analytics:7.0.0' (isso é ainda melhor, pois inclui apenas itens relacionados com gb e gtm)

    Eu tive a sorte de começair com 7.0.0 e vi o gtm trabalhair. Depois atualizou paira 7.3.0 e deixou de funcionair. Pode ser consertado com a nova lib. Gms.

    Tudo isso assumindo que você configurou seu contêiner. Se não ler mais sobre isso, acesse https://support.google.com/tagmanager/answer/6103657?hl=pt_BR&ref_topic=3441530

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.