Mobile app version of vmapp.org
Login or Join
Sent6035632

: Is it possible to track redirects to external sites from our subdomains? I have a handful of subdomains set up as redirects because we are using them for QR codes. I want to be able to track

@Sent6035632

Posted in: #Analytics #Cpanel #GoogleAnalytics #Redirects #Tracking

I have a handful of subdomains set up as redirects because we are using them for QR codes.

I want to be able to track the QR code redirects (which are already set up and printed so no changing them at this point) and see the effectiveness of each.

Here's two examples: qr.glorkianwarrior.com and ad.glorkianwarrior.com are set up to forward to our iTunes page (later on this year it may forward to Google Play or a specific landing page), is there any way on my server to track the redirect from the subdomain to iTunes and see where traffic is coming from first?

I have the redirects set up through cPanel presently using subdomains.

Edit: From the research I've seen I can't track a 301 directly. If I redirect to an internal page and then do a timed redirect to the iTunes link, how long will it take for the tracking script to track a hit?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

2 Comments

Sorted by latest first Latest Oldest Best

 

@Eichhorn148

If I redirect to an internal page and then do a timed redirect to the iTunes link, how long will it take for the tracking script to track a hit?


There is a better way of doing this than just waiting for a specific amount of time. Google Analytics event tracking supports a "call back" function that you can pass it. You can create such a call back function that changes the URL and it executes as soon as Google Analytics tracking has finished.

I implemented something like this and use the following function which wraps around Universal Analytics:

function logeventga(category, action, label, value, callback, nonAction){
var event = {
'eventCategory': category,
'eventAction': action
};
if (label) event['eventLabel'] = label;
if (value) event['eventValue'] = value;
if (callback) event['hitCallback'] = callback;
if (nonAction) event['nonInteraction'] = 1;
if (typeof ga == 'function' && ga.hasOwnProperty('loaded') && ga.loaded === true) {
ga('send', 'event', event);
} else if (callback) {
callback.call();
}
}


This method checks to see if Google Analytics is loaded so that the callback function gets executed even if the analytics js gets blocked by AdBlock.

You could use it something like this called from the onload event:

logeventga('redirect', 'redirect', href, null, function(){
window.location.href = href;
});


You would probably also want to set your Google Analytics snippet NOT to track a "pageview" on this particular page.

The disadvantage of using this approach would be that the redirect won't work for non-JavaScript enabled browsers and web crawlers. To make it work better for those browsers that would do a meta refresh after a few seconds if the JavaScript didn't execute for some reason. Google Analytics tracking usually executes within a few hundred milliseconds.

<meta http-equiv="refresh" content="5; url=http://example.com/">

10% popularity Vote Up Vote Down


 

@Kevin317

You can do this with PHP and Google Analytics.

For each subdomain run a index.php file that will send data to Google Analytics and then give a header redirect response to send the visitor to itunes. Google will record the events in analytics and the user won't see anything different.

Here is an example for a PHP redirect:
stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php
Here is the documentation for Google's Measurement Protocol API:
developers.google.com/analytics/devguides/collection/protocol/v1/
You can get details on the API here:
developers.google.com/analytics/devguides/collection/protocol/v1/reference
There is a PHP library on GitHub for this:
github.com/google/google-api-php-client

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme