Search code examples
androidgoogle-analyticsgoogle-tag-managergoogle-analytics-firebase

No data in GA with GTM for Android..?


Could someone help me out..?

There is no data being captured in GA. I use GTM for Android (latest versions) and I have already done the following things:

  • Set up the Google Play services SDK and added permissions to the Android manifest file.
  • Added a default GTM container to the project (binary).
  • Initialized GTM by the latest support pages of Google.
  • Pushed events and valus to the dataLayer.
  • I have set up GTM with the right tags, triggers and variable names and configuration.

This is most of the code that is used so far:

Splash activity

public class SplashActivity extends AppCompatActivity {
    private static final long TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS = 2000;
    private static final String CONTAINER_ID = "GTM-XXXXXX";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TagManager tagManager = TagManager.getInstance(this);

        if (Environment.get() != BaseEnvironment.PRODUCTION) {
            tagManager.setVerboseLoggingEnabled(true);
        }

        PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault(CONTAINER_ID, R.raw.gtm_xxxxxx);

        pending.setResultCallback(new ResultCallback<ContainerHolder>() {
            @Override
            public void onResult(ContainerHolder containerHolder) {
                ContainerHolderSingleton.setContainerHolder(containerHolder);

                if (! containerHolder.getStatus().isSuccess()) {
                    return;
                }

                Intent intent = new Intent(SplashActivity.this, NavigationActivity.class);
                startActivity(intent);

            }
        }, TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS, TimeUnit.MILLISECONDS);
    }
}

Info activity

@Override
public void onStart() {
    super.onStart();

    TagUtils.pushOpenScreenEvent(this, "Informatie");
}

@Override
protected void onStop() {
    super.onStop();

    TagUtils.pushCloseScreenEvent(this, "Informatie");
}

TagUtils

/**
 * Push an "openScreen" event with the given screen name. Tags that match that event will fire.
 */
public static void pushOpenScreenEvent(Context context, String screenName) {
    DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
    dataLayer.pushEvent("openScreen", DataLayer.mapOf(
            "screenName", screenName,
            "appVersion", appVersionName(context),
            "operatingSystem", systemVersion()
    ));
}

/**
 * Push a "closeScreen" event with the given screen name. Tags that match that event will fire.
 */
public static void pushCloseScreenEvent(Context context, String screenName) {
    DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
    dataLayer.pushEvent("closeScreen", DataLayer.mapOf(
            "screenName", screenName,
            "appVersion", appVersionName(context),
            "operatingSystem", systemVersion()
    ));
}

/**
 * Push a "scanProduct" event with the given screen name. Tags that match that event will fire.
 */
public static final String ACTION_PRODUCT_FOUND = "Product gevonden";
public static final String ACTION_PRODUCT_NOT_FOUND = "Product niet gevonden";
public static final String ACTION_PRODUCT_NOT_FOUND_CONNECTION_ISSUES = "Product niet opgehaald door verbindingsproblemen";

public static void pushScanProductEvent(Context context, String action, String code) {
    DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
    dataLayer.pushEvent("scanProduct", DataLayer.mapOf(
            "Category", "Scan",
            "Action", action,
            "Label", code
    ));
}

Manifest

    <activity
        android:name="com.google.android.gms.tagmanager.PreviewActivity"
        android:label="@string/app_name"
        android:noHistory="true">

        <intent-filter>
            <data android:scheme="tagmanager.c.nl.everybodylikespenguins" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>
        </intent-filter>

    </activity>

Please note I have hidden the container file ID and the data android:scheme="tagmanager.c.nl.everybodylikespenguins" is indeed the right name of the acceptation build of the app (Google also uses this in their example).


Solution

  • It looks like you're not calling containerHolder.getContainer() in the onResult callback. A call to getContainer is necessary to activate the container.