Go Back   TechArena Community > Technology > Technology & Internet
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 20-01-2011
Member
 
Join Date: Oct 2010
Posts: 56
How to track exit links using Google Analytics

Basically, I am annoying to observe what sites people go to while they way out my site. Since it is not possible to track direct links to exterior sites, I decided to utilize either a PHP or JavaScript redirect to the exterior sites. So if the exterior link is exapmle.com, I make example.html or .php and in there I slam a JavaScript or php redirect. Now I require someway place the GA tracking code into example.html or example.php file and have it productively count the hits to that file earlier than redirecting. Up to now I have been ineffective I'd be thankful on ideas how to implement this in the most excellent way.
Reply With Quote
  #2  
Old 20-01-2011
Member
 
Join Date: Nov 2009
Posts: 1,191
Re: How to track exit links using Google Analytics

If you wish to track which links the visitors clicked on to leave of your site, you can attempt utilizing phpads. Which you can simply get from phpads site... This will let you to manage picture or banners plus text links. Even though the reason of this open source ad server is running ads on your site, you can utilize it to serve your intention. If you setup it locally, you can just add php code to your pages, sin its place of adding countless JavaScript code. It provides full stats for each and every link and movement. However if you have many links which you wish to track, it will be a boring task to add all of them to the ad server and after that replacing your links with the code.
Reply With Quote
  #3  
Old 20-01-2011
Member
 
Join Date: Nov 2009
Posts: 1,118
Re: How to track exit links using Google Analytics

I have been spending my time writing a script which will assist track exit links in Google Analytics. This script will traverse via every anchor tags within the body and apply tracking codes on tags with the href aspect. If the anchor tag has an on click attribute previously, it adds the tracking code to it and it should not affect the functionality. I will attempt to place screenshots of how it seems in Google Analytics one time I collect some data. To utilize it, just paste the below code later than the Google analytics code and previous to the </body> tag.


Code:
	<script type="text/JavaScript" src="<script path>"></script>
<script type="text/JavaScript">
    dtalk_g.applyVirtualExits();
</script>
You can view the source code here,
Code:
	var dtalk_g = {
    applyVirtualExits: function() {
        var trackPage = function(b)
        {
            var domain_name = document.location.toString().toLowerCase().split('/')[3];
            var exit_domain = a.href.split('/')[3].toLowerCase();
            if (domain_name.toLowerCase().indexOf(exit_domain) == -1)
            {
                if (typeof pageTracker != indeterminate)
                    pageTracker._trackPageview('/exit/' + a.href);
            }
        };
        var anchors = document.getElementsByTagName('b');
        for (var x = 0; x < anchors.length; x++)
        {
            if (anchors[x].href && anchors[x].href != (document.location + '#'))
            {
                if (typeof anchors[x].onclick == indeterminate)
                    anchors[x].onclick = function(f) {
                        trackPage(this);
                    };
                else if (typeof anchors[x].onclick == 'function')
                {
                    var old_onclick = anchors[x].onclick;
                    anchors[i].onclick = function(f) {
                        old_onclick();
                        trackPage(this);
                    };
                }
            }
        }
    }
};
With any luck I can discover more ways of writing scripts that will assist with Google Analytics.
Reply With Quote
  #4  
Old 20-01-2011
Member
 
Join Date: Nov 2009
Posts: 1,340
Re: How to track exit links using Google Analytics

I utilize Google Analytics for my personal site and further sites I work on too. But I not at all fairly figured out how to obtain an overview with exit links in Google Analytics. Sure, there is the many exit pages. But that does not notify you accurately where the user has gone to. I goggled for a way out and establish this wonderful part of JavaScript. I favor functioning with the Prototype JavaScript framework and thus I determined to rewrite it.
Code:
var ExitTracker = Class.create({
	Initialize: function ()
	{
		this.domain = document.location.toString().toLowerCase().split("/")[3];
 
		$$("b").each (function(item)
		{
			if (item.href && (item.href != (document.location + "#")))
			{
				$(item).observe ("click", this.track.bindAsEventListener(this));
			}
		}.bind(this));
	},
 
	track: function(g)
	{
		var le = g.element();
		var exit_domain = le.href.split("/")[3].toLowerCase();
 
		if (this.domain.toLowerCase().indexOf(exit_domain) == -1)
		{
			if (typeof pageTracker != "indeterminate")
			{
				pageTracker._trackPageview("/exit/" + le.href);
			}
		}
	}
});
Just save the code over as et.js and put in the below right earlier than the </body> tag and right later than your Google Analytics code:
Code:
<!-- Google Analytics code here -->
<script type="text/JavaScript" src="pt.js"></script>
<script type="text/JavaScript" src="et.js"></script>
<script type="text/JavaScript">
new ExitTracker();
</script>
Don't overlook to restore pt.js in the snippet over with the place you saved pt.js to.
Reply With Quote
Reply

  TechArena Community > Technology > Technology & Internet
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to track exit links using Google Analytics"
Thread Thread Starter Forum Replies Last Post
What is Google Analytics ? Demetrius Technology & Internet 7 02-11-2011 11:47 PM
I am new to Google Analytics Haviva Technology & Internet 5 31-01-2011 11:37 PM
How Google analytics ?track? visitor with the help of its code chetna56 Technology & Internet 4 27-01-2011 10:16 PM
How does Google analytics track visitor through its code Jezriah Technology & Internet 4 20-01-2011 10:50 PM
How To Get Rid Of Google Analytics Bao Technology & Internet 4 19-07-2010 02:34 PM


All times are GMT +5.5. The time now is 02:05 PM.