Mobile app version of vmapp.org
Login or Join
Murray155

: Generate Virtual Pageview via .js OnClick event in Google Analytics I have some expanding sections (via .js) and I want to see when the user clicks those. So, in the OnClick event I want to

@Murray155

Posted in: #GoogleAnalytics #Javascript

I have some expanding sections (via .js) and I want to see when the user clicks those.

So, in the OnClick event I want to attach some .js to fire off a virtual pageview. (I know how to fire an Event but I want a Pageview so I can use it in Goals)

And here is the .js I'm using .

I suspect I can just change the 'event' parameter to something else (pageview ??)

<script>

/**
* Function that tracks a click on an outbound link in Analytics.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murray155

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

According to Google Analytics Docs, "pageview hits can be sent using the send command and specifying a hitType of pageview"

Example in your case :

<script>

/**
* Function that tracks a click on an outbound link in Analytics.
*/
var trackOutboundLink = function(url) {
ga('send', 'pageview', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>


I would test it, since I am not sure that hitCallbackis supported in this case. If not, Google suggest another (similar) format in its doc.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme