title: Right way to setup google analytics on a razor page in asp netcore
body: <p>I currently have some forms, 6 in total, built on razor so I want to track how many times each form is sent.</p>
  
  <p>On Google Analytics I created a goal and set it as custom, the category is count, the action is click, the label is houseform and the value is 0.</p>
  
  <p>In my solution for the forms I have the following, the code for the analytics I copy paste in from the dashboard.</p>
  
  <p>I followed or try to followed the Analytics guide but I just cant make it work, on my goals dashboard this goal appears as 0 and I let more than 24h to fetch information just in case it doesn't appear immediately.</p>
  
  <p>Can someone give me an advice on how to make this work, I have to make this exact thing on more forms, so any help is highly appreciated.</p>
  
  <p><strong>_Layout.cshtml</strong></p>
  
  <p>This is inside the head tag</p>
  
  <pre><code>&lt;!-- Global site tag (gtag.js) - Google Analytics --&gt;
  &lt;script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-X"&gt;&lt;/script&gt;
  &lt;script&gt;
              window.dataLayer = window.dataLayer || [];
              function gtag()
  
              {dataLayer.push(arguments);}
  
              gtag('js', new Date());
  
              gtag('config', 'UA-XXXXXX-X');
  &lt;/script&gt;
  </code></pre>
  
  <p>And this is the form tags I'm using</p>
  
  <pre><code>@{
  ViewData["Title"] = "Create";
  }
  
  &lt;hr /&gt;
  &lt;div class="row"&gt;
      &lt;div class="form-row"&gt;
          &lt;form method="post" id="razorForm"&gt;
              &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
              &lt;div class="form-group col-md-6"&gt;
                  &lt;label asp-for="HouseQuote.Name" class="control-label"&gt;Nombre&lt;/label&gt;
                  &lt;input asp-for="HouseQuote.Name" class="form-control" placeholder="Nombre" /&gt;
                  &lt;span asp-validation-for="HouseQuote.Name" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group col-md-6"&gt;
                  &lt;label asp-for="HouseQuote.Email" class="control-label"&gt;Email&lt;/label&gt;
                  &lt;input asp-for="HouseQuote.Email" class="form-control" placeholder="Email" /&gt;
                  &lt;span asp-validation-for="HouseQuote.Email" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group col-md-6"&gt;
                  &lt;label asp-for="HouseQuote.OwnerType"&gt;¿Eres?&lt;/label&gt;
                  &lt;select class="form-control" id="exampleFormControlSelect1" asp-for="HouseQuote.OwnerType"&gt;
                      &lt;option value="Propietario"&gt;Propietario&lt;/option&gt;
                      &lt;option value="Inquilino"&gt;Inquilino&lt;/option&gt;
                      &lt;option value="Arrendador"&gt;Arrendador&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;span asp-validation-for="HouseQuote.OwnerType" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group col-md-6"&gt;
                  &lt;label asp-for="HouseQuote.HouseValue" class="control-label"&gt;¿Cuál es el valor de la casa?&lt;/label&gt;
                  &lt;input asp-for="HouseQuote.HouseValue" class="form-control" placeholder="¿Cuál es el valor de la casa?" type="number" min="0" /&gt;
                  &lt;span asp-validation-for="HouseQuote.HouseValue" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group col-md-6"&gt;
                  &lt;label asp-for="HouseQuote.HouseContentValue" class="control-label"&gt;¿Cuál es el valor de los contenidos?&lt;/label&gt;
                  &lt;input asp-for="HouseQuote.HouseContentValue" class="form-control" placeholder="¿Cuál es el valor de los contenidos?" type="number" min="0" /&gt;
                  &lt;span asp-validation-for="HouseQuote.HouseContentValue" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group col-md-6"&gt;
                  &lt;label asp-for="HouseQuote.ZipCode" class="control-label"&gt;Código Postal&lt;/label&gt;
                  &lt;input asp-for="HouseQuote.ZipCode" class="form-control" placeholder="Código Postal" type="number" min="0" /&gt;
                  &lt;span asp-validation-for="HouseQuote.ZipCode" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group" style="margin-left: 15px; margin-right: 15px;"&gt;
                  &lt;label asp-for="HouseQuote.TelephoneNumber" class="control-label"&gt;Teléfono&lt;/label&gt;
                  &lt;input asp-for="HouseQuote.TelephoneNumber" class="form-control" placeholder="Teléfono" type="number" min="0"/&gt;
                  &lt;span asp-validation-for="HouseQuote.TelephoneNumber" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group" style="margin-left:15px;"&gt;
                  &lt;input type="submit" id="submitProcess" value="Enviar" class="btn btn-primary" onclick="gtag('event', 'click', {'event_category':'count','event_label':'houseform','value':'0'});" /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
          &lt;div id="load-container"&gt;
              &lt;div id="loader" class="loader my-auto text-center"&gt;&lt;/div&gt;
              &lt;p class="text-center"&gt;Por favor espere, estamos enviando su solicitud&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  
  }
  </code></pre>