Results 1 to 4 of 4

Thread: How to track exit links using Google Analytics

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

Similar Threads

  1. What is Google Analytics ?
    By Demetrius in forum Technology & Internet
    Replies: 7
    Last Post: 02-11-2011, 11:17 PM
  2. I am new to Google Analytics
    By Haviva in forum Technology & Internet
    Replies: 5
    Last Post: 31-01-2011, 11:07 PM
  3. How Google analytics ‘track’ visitor with the help of its code
    By chetna56 in forum Technology & Internet
    Replies: 4
    Last Post: 27-01-2011, 09:46 PM
  4. How does Google analytics track visitor through its code
    By Jezriah in forum Technology & Internet
    Replies: 4
    Last Post: 20-01-2011, 10:20 PM
  5. How To Get Rid Of Google Analytics
    By Bao in forum Technology & Internet
    Replies: 4
    Last Post: 19-07-2010, 02:04 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,638,077,843.25470 seconds with 17 queries