blazor-analytics icon indicating copy to clipboard operation
blazor-analytics copied to clipboard

GTM Preview mode not supported?

Open mark-at-tusksoft opened this issue 5 years ago • 4 comments

This may be an issue separate from Blazor-Analytics (let me know if you agree). When trying to view the BlazorClient site in preview mode using GTM, the expected panel does not appear. Is this just an incompatibility with Blazor? I'm not sure if GTM needs to inject additional js to make this functionality work or if it is supposed to be included in the initial analytics scripts from the head element to insert the preview/debug iframe.

mark-at-tusksoft avatar Sep 23 '20 23:09 mark-at-tusksoft

Found the issue. GoogleAnalytics/Resources/GoogleAnalyticsInterop.ts line 25 script.src = "https://www.googletagmanager.com/gtag/js?id=" + trackingId; looks like this should be script.src = "https://www.googletagmanager.com/gtm.js?id=" + trackingId;

I get a 403 when it is /gtag/js instead of /gtm.js

mark-at-tusksoft avatar Sep 24 '20 00:09 mark-at-tusksoft

Hi Mark, please correct me if I'm wrong.

The library only supports GTAG atm, which is implemented inside GoogleAnalyticsInterop.ts. If you wanted to use GTM, a new integration would need to be added since the apis are different.

I also found that some browsers with adblockers block the gtag.js script from being loaded, can you check if that's your case?

isc30 avatar Sep 24 '20 15:09 isc30

This is very likely a result of my ignorance around Google services. I was unaware there was a difference. Perhaps the 403 I was getting was due to .../gtag/js being handed a GTM id.

How involved of a process would it be to include GTM? I kinda see how it would be done from the Blazor-side of the Blazor-Analytics infrastructure but my experience with GTM is rather limited so I am oblivious to how much work would be required for the typescript wrapper.

mark-at-tusksoft avatar Sep 24 '20 16:09 mark-at-tusksoft

I also needed GTM support so I forked the repo and tried to support it. It is far to be perfect (for example variables to use in GTM for events and events name are hardcoded) but could be a starting point: https://github.com/pmonte/blazor-analytics

pmonte avatar Jul 23 '21 07:07 pmonte