Search code examples
androidgoogle-tag-manager

Android GTM: 400 bad request to preview


I am using Java to develop an Android app with Android-type GTM. After setting up, I published the container and wanted to preview the container. I generated a preview link and used adb command to preview it. However, it turned out to be a 400 error.

400. That's an error.
The server cannot process the request because it is malformed. It should not be retried. That's all we know.

Here is an example of the begin preview link:

adb shell am start -a "android.intent.action.VIEW" -d "tagmanager.c.com.dynamic_link_alternative://preview/p?id=GTM-XXXXXXX\&gtm_auth=zGwb1hAaQs5X09iwrEmoIw\&gtm_preview=14"

When I used it, there was a popup message saying:

Preview
Preview mode updated

Once tapped to continue, it went to the 400 error page. What I've tried:

  1. Checked the quotas that it would show 403 if over quotas
  2. Followed the official docs to install GTM; the current version is 5
  3. Confirmed the container had been published, and the published version is live
  4. Uninstall the app, re-launch and re-run the app

Is there anything I missed? Any help is highly appreciated.


Solution

  • When I first installed the script, I got the log saying:

    Ignoring container asset GTM-XXXXXXX_v14.json (does not match (gtm-[a-z0-9]{1,10})\.json)
    

    I managed it into the correct regex matching and the error mentioned popped up. Fortunately, I tried the GTM-XXXXXXX.json format, with all capital letters, and it worked eventually.