Google analytics and redirect pages


(Neil Newman) #1

I understand that if you use a redirect page then Google Analytics will not record button clicks, as there is no place to put the Google code into a redirect page.

 

I see a post already covering this subject, that suggests using a standard page containing the Google Analytics code within it and using an onload attribute that redirects the page.

 

Has anyone got an example of how I would implement this "onload attribute", I presume it is a piece of JavaScript?

 


(Joel Porgand) #2

Unless you've got a specific reason to track the redirect as well then I can't see the point - you can record a click event on the originating page & you'll get a pageview on the page you're redirecting to anyway. 


(Anewport) #3

You could probably create a Trigger that fires on Asset Accessed for Redirect Pages and then use Call REST Resource which goes to Google Analytics and pass in a few keywords and cookie values to send on for analysis.

 

Come to think of it, if this was to work then you could do it for all non-page asset types like files (PDF, etc).

 

Let me know how you go - would be very keen to hear if this works. Might test it myself if I have the time.


(Nic Hubbard) #4

You could use jQuery and a click event. All you would need to do is give your redirect page link a class:

// Redirect Page
$(".redirect").click(function() {
   ga('send', 'event', 'button', 'click', $(this).attr('title'));
});

And as chickensoup64 suggested, you can do the same with file links:

$("a[href*='.pdf'], a[href*='.doc'], a[href*='.xls'], a[href*='.ppt']").click(function() {
    var url = $(this).attr('href');
    ga('send', 'event', 'button', 'click', 'Document '+$(this).attr('href'));
});