Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google tag manager won't push event's to datalayer on Android

I'm trying to implement Tag Manager in my Android Application following this guide, but for some reason I can't push event's to the datalayer.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TagManager tagManager = TagManager.getInstance(getApplicationContext());
    TagManager.getInstance(getApplicationContext()).setVerboseLoggingEnabled(true);

    PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferFresh(GOOGLE_TAG_MANAGER_CONTAINER_ID, R.raw.gtm_default_container_v2);
    pending.setResultCallback(new ResultCallback<ContainerHolder>() {
        @Override
        public void onResult(ContainerHolder containerHolder) {
            TagManager.getInstance(getApplicationContext()).getDataLayer().push("event", "screenName");
            // Using the "pushEvent" method doesn't work either
            // TagManager.getInstance(getApplicationContext()).getDataLayer().pushEvent("screenName", DataLayer.mapOf());
        }
    }, 2, TimeUnit.SECONDS);
}

When I try to run my app, all my log is saying is this

V/GoogleTagManager﹕ Attempting to load a container from the resource ID 2131099649 (com.example.cpe.gatestapp:raw/gtm_default_container_v2)
V/GoogleTagManager﹕ Deleted 0 expired items
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
V/GoogleTagManager﹕ The container was successfully loaded from the resource (using binary file)
E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
V/GoogleTagManager﹕ Attempting to load resource from disk
V/GoogleTagManager﹕ loadAfterDelay: containerId=GTM-XXXXXX delay=0
D/GoogleTagManager﹕ Setting previous container version: MQ$0
E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
V/GoogleTagManager﹕ The Disk resource was successfully read.
V/GoogleTagManager﹕ Start loading resource from network ...
V/GoogleTagManager﹕ Successfully loaded supplemented resource: zzi_p: "MQ$0"
V/GoogleTagManager﹕ No change for container: GTM-XXXXXX
V/GoogleTagManager﹕ loadAfterDelay: containerId=GTM-XXXXXX delay=43200000
D/GoogleTagManager﹕ Setting previous container version: MQ$0
E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
V/GoogleTagManager﹕ setting refresh time to current time: 1435818825632
V/GoogleTagManager﹕ Load resource from network finished.

Screenshots from my GA and Tag Manager accounts:

tigger's

TagManager screen

Google analytics dump

like image 735
Eixx Avatar asked Nov 10 '22 10:11

Eixx


1 Answers

The answer to my question is pretty simple after I figured it out.

So I have created an Analytics Tracker which track's if my application crashes. I have made a option, that if i'm running my application in debug mode aka running it from AndroidStudio, my Tracker will make a 'dryRun'.

So I figured that the TagManager is using the Analytics tracker to send all the events. Which is why it helped to disable the dryRun on my GoogleAnalytics tracker.

like image 117
Eixx Avatar answered Nov 14 '22 22:11

Eixx