Rails beginner
Rails beginner

Reputation: 14504

Google Analytics how to track fake pageview?

How do I create a fake pageview in GA?

Example

<a href="#" onclick=>"javascript: pageTracker._trackPageview('/billigst_klik');">Track</a>

Then GA would track one pageview named "billigst_klik"

Upvotes: 2

Views: 7123

Answers (2)

jk.
jk.

Reputation: 14435

function track(someurl){
    _gaq.push(['_trackPageview', someurl]);
}

<a href="#" onclick="track('/billigst_klik');">Track</a>

But if you are tracking just clicks, it should be an event not a pageview.

function trackEvent(someurl){
     _gaq.push(['_trackEvent', 'Click', 'Link_Click', someurl]);
}

<a href="#" onclick="trackEvent('/billigst_klik');">Track</a>

Click is the category and Link_Click is the action. someurl is the label. You can set them to be whatever values makes sense to you.

Guide to Google Analytics Event Tracking

Upvotes: 10

David Brainer
David Brainer

Reputation: 6331

Are you using the newer async code? If so, something like this should work:

<a href="???" onclick="_gaq.push(['_trackPageview', '/billigst_klik']); return false;">Track</a>

Upvotes: 1

Related Questions