Google Analytics uses a JavaScript snippet to do all the tracking. No JavaScript runs on redirect requests. That means that Google Analytics can't track redirects directly. There are two approaches I use for this type of tracking:
Campaigns
If these redirects are tracking clicks from other sites, then you probably want to use Google Analytics campaign tracking features for them. To do so, have the redirect script append additional utm
parameters to the redirect URL. Use the Google Analtyics URL builder to determine what the parameters should actually be. You could put the type
and id
into the utm_content
or utm_source
parameter, for example.
I use this method to track alternate domain names. When somebody types in my alternate domain alternate.example.com
they get redirected to my real site with these types of parameters: www.example.com/?utm_campaign=domainnames&utm_medium=domain&utm_source=alternate.example.com
The data that I'm looking for then appears in Google Analytics under "Acquisition" → "Campaigns" → "domainnames".
You wouldn't want to use this type of tracking if these redirects are from your own site and you are planning to track other external campains. A user can only be attributed to one campaign at a time.
Cookies and events
Another way is to have the the redirector store the type
and id
to a cookie. Then the next pageview can report these items to Google Analytics as events.
You would have to include some JavaScript on every page that:
- Looks for the cookie with
type
and id
.
- Uses JavaScript like this to send an event:
ga('send', 'event', 'trackedredirect', type + " " + id, {'nonInteraction': 1});
- Deletes the cookie.
Once you did that, it would appear in Google Analytics under "Behavior" → "Events" → "Top Events" → "trackedredirect".