Goal
As described in the title, I wish to inject some HTML, which loads Google Analytics, which only activates once the user accepted cookies and a specific cookie is set and is true. I followed these answers: Check if Cookie Exists
My try
@{
using System.Net.Http;
if (HttpContext.Current.Response.Cookies.AllKeys.Contains("cookieNameHere"))
{
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=idhere"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-codehere');
</script>}}
Errors
It complains about the HttpContext, saying that it's not available in the current context and hence I tried to import it without any avail...