Google analytics to laravel page

im trying to add google analytics to my page. I have created analytics.blade.php with code like this:

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'Analytics_ID', 'auto');
  ga('send', 'pageview');


and added @include (‘analytics’) to app.blade.php

But i cant get any info in google analytics of that page. Maybe i have something more to do, or what?


Analytics snippet like G-XXXXXXXX is for Google Analytics 4 while your code is for Google Analytics Universal. So you have to use this snippet in this case (gtag library instead of ga):

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXX');

Leave a Reply

Your email address will not be published. Required fields are marked *