Google Tag Manager Preview working on localhost but not on live

I’ve included and configured @frontity/google-tag-manager-analytics as follows:

const settings = {
    state: {
      frontity: { ... },
      analytics: {
        pageviews: {
          googleTagManagerAnalytics: true
        },
        events: {
          googleTagManagerAnalytics: true
        }
      }
    },
    packages: [
      { ... },
      { ... },
      {
        name: '@frontity/google-tag-manager-analytics',
        state: {
          googleTagManagerAnalytics: {
            containerId: 'GTM-TVDXX9P'
          }
        }
      },
      ...
    ]
  }

When I try the “Preview” button on the Google Tag Manager admin site, if I try localhost:3000 with my development server running, I get a connection pretty quickly and confirmation that I’ve set it up correctly. However, if I try to run any of the domains that are associated with this deployment on Vercel (https://microbeninja.com, https://annihilyzer.microbeninja.com, https://depot.microbeninja.com, or https://store.microbeninja.com), I get a timeout error. I’ve tried with and without my adblocker on and with and without Firefox’s tracker protection on. With the localhost:3000 connection, it was working fine with tracking and adblocking enabled anyway. I can also see that the gtm.js is included and looks exactly the same on local development as it does on the live site.

Repo is at https://gitlab.artlyticalmedia.com/artlytical-media/microbe-ninja-frontity-theme/.

Thanks for any help you can provide!

I ended up using Google Analytics and @frontity/google-analytics, which immediately worked, but I believe this is the second time I’ve tried to use Google Tag Manager for analytics with Frontity and it didn’t work. I believe this is still an issue because the Google Analytics only works with Universal Analytics and not the new Google Analytics 4, which will probably be forced on all of us sooner than later.

1 Like

@SantosGuillamot we should take this into consideration and be ready to update our package.

I’ve just tested it in our own web, frontity.org, which is using GTM and Vercel as well, and it works fine in the live environment. I’ve tried with both Google Chrome and Firefox, so I’m not sure what could be the issue. In the past, I have also encountered issues with GTM preview and sometimes they were solved accessing in Incognito mode if you want to try.

By the way, the pageviews and events are enabled by default for both @frontity/google-tag-manager and @frontity/google-analytics, so you don’t have to specify that in your frontity.settings.js as you are doing here.

Regarding this, you are totally right. Thanks a lot for pointing it out :slightly_smiling_face: . I’ve created an issue to solve it. I tested it quickly and it shouldn’t be difficult to adapt.

By the way, if you’d like to collaborate and make a Pull Request to fix it, we would be more than happy to help you with anything you need :slightly_smiling_face:.