user3869231 user3869231 - 20 days ago 4
Ajax Question

Google Analytic Page View with Modal/Overlay Ajax Content

I am setting up a WordPress tool where the user clicks a link, and a single post is pulled from the database and inserted into a modal/overlay. (exactly like

Now, since the user is not visiting the actual page, I am assuming there is no way to track it as a "page view" to get the "time spent on page" and other important page-related stats.

I do know that I can track the URL event, but just tracking the URL click is not enough.

Is there a way to achieve tracking the modal content as a page view for the actual post URL pulled into the modal? Thanks in advance.


This is possible, but not easy to answer without seeing the code that calls your overlay.

Basically you would look if your modal function provides a callback (a javascript function that is run after the code has executed) and provide a "virtual pageview", i.e. run a pageview call and pass in a custom path that indicates the modal window:

ga('send', 'pageview', '/modal/path/to/post/');

The path you provided as extra parameter will appear in your content reports as a page. If you also want to provide a title (or override any other field in GA) you can pass a JSON object as third parameter:

ga('send', 'pageview', {
    title:'my title' 

Since this is tagged ajax - you can put the pageview into the callback for the ajax success event so it will be fired only when the page is actually loaded.