1

i try to figure out this problem since a few days but i'm stuck.

I want that Google Analytics count each hash url from my gallery as a page view. I use Grand Media Gallery, with photobox template. >> http://codeasily.com/portfolio-item/gmedia-photobox/

If you click on a picture, a new url is load ex : http://codeasily.com/portfolio-item/gmedia-photobox/#photoBox-43

Unfortunately, GA doesn't count that for a page view. Or i need that stats to know which image is the most viewed on my website.

I try to add that to GA tracking code :

<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-17649764-10', 'auto');
      ga('send', 'pageview', {'page': location.pathname+location.search+location.hash});

window.onhashchange = function() {
    ga('send', 'pageview', {'page': location.pathname+location.search+location.hash});
}; </script>

But that's not work neither...

i already found that question Google Analytics Setting Up A PageView On Hash Change

But i'm not using isotope, and i already add this to GA tracking code without result. My problem is the page doesn't reload whent users watch my photos...

ga('send', 'pageview', {'page': location.pathname + location.search + location.hash});

Thank you for your help,

Foub

Community
  • 1
  • 1
Foub
  • 255
  • 1
  • 3
  • 16
  • Possible duplicate of [Google Analytics Setting Up A PageView On Hash Change](http://stackoverflow.com/questions/32378607/google-analytics-setting-up-a-pageview-on-hash-change) – nyuen Mar 16 '16 at 15:13
  • I already see that post but that doesn't help me. I don't use isotope – Foub Mar 16 '16 at 15:20

1 Answers1

1

You can do that with Google Tag Manager. The main GA tracking code is fired on trigger History Source equals pushState, in addition to the standard All Pages trigger. And you just need to specify the page path with the fragment in a JS variable, like this:

function() {
  return {{Event}} === 'gtm.historyChange' && {{New History Fragment}} ? {{Page Path}} + '#' + {{New History Fragment}} : undefined;
}
maggieto
  • 613
  • 6
  • 10
  • Thank you. But i'm still confuse about Google Tag Manager. I configure the Tag like this : The Tag // Google Analytics // Universal Analytics //my GA ID // page view. Fields to Set : Field name : page / Value : {{page path with hashtag}} The Trigger // Choose Event : History Change // Fire On : History Source equals pushState Variable // Choose type : Custom Javascript // Configure variable : Your Custom JS Is that the good way to configure Google Tag Manager. When i try GA in real time, the hash url is count only on the page reload... – Foub Mar 17 '16 at 08:22
  • Thank you, your function solve my problem, i configure Google Tag Manager like this : I associate Event - History Fragment Change and All Pages on firing triggers. And it works ! – Foub Mar 17 '16 at 08:38
  • Great! Yes - you need two triggers so the tag is fired on either one. – maggieto Mar 18 '16 at 09:24