SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict capescafe's Avatar
    Join Date
    Dec 2004
    Location
    Bellevue, WA
    Posts
    222
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question onclick="pageTracker._link..." from Google Analytics -- need help with code

    I'm using Google Analytics on my site and the site I'm using it on has a section of it that still uses frames. (Yes I know frames are horrible and outdated...but we still need them for this section of our site). Anyways, I'm using the code on some links that go to another URL where I need to use the code for tracking links across multiple domains. So my link looks like this:

    <a href="http://www.otherurl.com" onclick="pageTracker._link(this.href); return false;" target="_top">Go to Other URL</a>

    My problem is though that even though I have target="_top" in the href tag the new URL still loads into the frame itself instead of loading in the whole browser window and leaving the frames pages. I'm thinking that I need to change something in the onclick javascript code. Does anyone know what I can change in the javascript code to make this work and still be able to track my links? I've posted this on the Google Analytics help forum but no one was able to help, so thought I'd post it here. If I take out the onclick part the link works just fine. So I know it has something to do with the javascript portion.
    Carolyn (cape's cafe)
    Twitter | My Treehouse Profile | eBookFling

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out this site if you haven't already if are trying to track outbound links:
    http://www.google.com/support/google...n&answer=55527

    With the function that you add to your head you could modify it to be similar to the following:

    Code:
    <script type="text/javascript">
    function recordOutboundLink(link, category, action) {
      try {
        var pageTracker=_gat._getTracker("UA-XXXXX-X");
        pageTracker._trackEvent(category, action);
        setTimeout('framename.document.location = "' + link.href + '"', 100)
      }catch(err){}
    }
    </script>
    Let us know if you need anymore help

  3. #3
    SitePoint Addict capescafe's Avatar
    Join Date
    Dec 2004
    Location
    Bellevue, WA
    Posts
    222
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't framename.document.location open up the link in the same frame? How do I make it so that when the link is clicked it leaves the frames and opens. Not in a new window, just outside the frameset. The equivalent of target="_top".
    Carolyn (cape's cafe)
    Twitter | My Treehouse Profile | eBookFling

  4. #4
    SitePoint Addict capescafe's Avatar
    Join Date
    Dec 2004
    Location
    Bellevue, WA
    Posts
    222
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well I got it to work. Instead of framename.document.location I used window.top.location and it works!
    Thanks SlickAU by the way for your help.
    Last edited by capescafe; Jun 8, 2010 at 09:56. Reason: Needed to say Thanks.
    Carolyn (cape's cafe)
    Twitter | My Treehouse Profile | eBookFling

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Ahh yes, us old timers remember the heedy days of breaking out of frames

    Use top.location.href = document.location.href;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •