1

I am very new to ASP NET Core razor pages. I have a requirement to set up Google Tag Manager in ASP NET Core razor pages. Usually in the ASP.Net solution we use Google Analytic's tag.js script in page load. In angular we usually set up in app.module.ts and app.component.ts.

But, I am to set up GTM tracking code and id in ASP NET Core razor pages.

After set up, I need to send triggering conditions to GTM (like on button click send a event trigger to GTM so that it will in turn call the Google Analytics set up tag). Is there any helper class or plugins which I can use for the same? Or in which file like Startup.cs, I can use the GTM configuration set up?

1 Answer 1

1

I have not used Razor Pages, but it looks like it allows you to have an HTML template, i.e. HTML that is reused site-wide or on groups of pages.

So you would just need to get your tracking code and put it into the <head> section of all pages. This post addresses how to run Javascript tags in a similar fashion: https://stackoverflow.com/questions/4311783/asp-net-mvc-3-razor-include-javascript-file-in-the-head-tag

Once Tag Manager is set up, you can run GA from a GTM tag that fires on all pages.

2
  • 1
    Thank you for the reply !
    – Annas
    Commented Jul 6, 2021 at 6:18
  • 1
    You're welcome, let me know if theres anything else I can help with here.
    – Jake 1986
    Commented Jul 6, 2021 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.