I am trying to implement Google Tag Manager by following this tutorial: https://developers.google.com/tag-manager/android/v4/
When I run the application, I get in the console these errors :
05-22 12:27:44.490 V/GoogleTagManager﹕ Attempting to load a container from the resource ID 2131099650 (testconverteo.ismail.converteotag: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
And I have no data in Google Analytics in real time, even more nothing which proves that my application is tracked.
If anybody has had the same problem , or he had followed the same steps and knows how to resolve this issue, please leave an explanation in comment.
The steps I've done:
compile 'com.google.android.gms:play-services:7.3.0'
What I currently have in my splash screen activity is the following:
public class SplashScreenActivity extends Activity {
private static final String CONTAINER_ID = "GTM-XXXX";
@Override
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>() {
@Override
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());
startMainActivity();
}
}, 2, TimeUnit.SECONDS);
}
private void startMainActivity() {
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener {
@Override
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());
}
}
}
And in the main Activity:
public void onStart() {
super.onStart();
DataLayer dataLayer = TagManager.getInstance(this).getDataLayer();
dataLayer.pushEvent("Application ouverte", DataLayer.mapOf("login page","un de plus"));
}
And I’ve also created this 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;
}
}
Please note I've hidden the Google Tag Manager container ID
Let me know if anybody wants more information
Thank you
Replace line
compile 'com.google.android.gms:play-services:7.3.0'
with
compile 'com.google.android.gms:play-services:7.0.0'
or
compile 'com.google.android.gms:play-services-analytics:7.0.0'
(that's even better as it just includes ga and gtm related stuff)
I was lucky enough to start with 7.0.0 and saw gtm working. Then upgraded to 7.3.0 and it just stopped working. It might be fixed with new gms lib.
All that assuming you've configured your container. If not read more about that here https://support.google.com/tagmanager/answer/6103657?hl=en&ref_topic=3441530
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With