7 Replies Latest reply on May 6, 2006 4:23 PM by etman

    Track anchor clicks

    etman
      I have a one-page newsletter-type website that has several anchor links that I need to try and track when someone selects them.

      Any thoughts?

      Thanks in advance,
      Rob
        • 1. Re: Track anchor clicks
          Level 7
          Put a page in between the link and the landing page.

          In other words. Have the anchor links actually point to a separate page
          (passing the anchor along). Then have that page log what anchor was passed
          and redirect the user back to the appropriate page and anchor.

          --
          Bryan Ashcraft (remove brain to reply)
          Web Application Developer
          Wright Medical Technologies, Inc.
          =============================
          Macromedia Certified Dreamweaver Developer
          Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


          "etman" <webforumsuser@macromedia.com> wrote in message
          news:e3d6p3$b5n$1@forums.macromedia.com...
          >I have a one-page newsletter-type website that has several anchor links
          >that I need to try and track when someone selects them.
          >
          > Any thoughts?
          >
          > Thanks in advance,
          > Rob


          • 2. Re: Track anchor clicks
            etman Level 1
            I thought of that too, but I'd like to avoid loading extra pages if necessary.

            What about this:
            1. person clicks on an anchor
            2. Same page loads but at the top is some CF: registers anchor link clicked and if anchor is different than session variable (or session variable is empty) it registers a hit, updates the session variable and then goes down to said anchor.

            I'm close to getting this to work, I just need to get the redirect to work cleanly. I'd like to limit the number of times pages reload if possible.
            • 3. Re: Track anchor clicks
              Dan Bracuk Level 5
              If an anchor is clicked, you can use the cgi.http_referrer variable to do your count. Of course, users can hide that from you, so you might miss some.

              You could attach url variables, but, if the user bookmarks the target page, you might double count.

              • 4. Re: Track anchor clicks
                etman Level 1
                But isn't cgi.http_referrer where you're coming from? I want to track where you're going to.
                • 5. Re: Track anchor clicks
                  Dan Bracuk Level 5
                  quote:

                  Originally posted by: etman
                  But isn't cgi.http_referrer where you're coming from? I want to track where you're going to.

                  If you use it on your target page, you know that the user got there by using a hyperlink.
                  • 6. Track anchor clicks
                    drforbin1970 Level 1
                    Use CF and JavaScript. Create the cookie initially with CF. Update the cookie when user clicks with JavaScript. Read the updated cookie on every page load with CF using your APPLICATION.CFM file. Write the value to a DB, etc. Copy the below and run. Should be what you need. You might need more error checking, I concentrated on functionality. The onLoad() in the BODY tag initializes the JavaScript input box counter and is not required. If not needed, remove the onLoad() call, the initializeKounter() function and one line from updateCookie() (which is commented).

                    You owe me a beer


                    <cfparam name="COOKIE.ANCHOR_KOUNTER" default="0">

                    <cfoutput>
                    CF anchor cookie count: #cookie.anchor_kounter#<br>
                    </cfoutput>

                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

                    <html>
                    <head>
                    <title>Untitled</title>

                    <script language="JavaScript">
                    function updateCookie() {
                    var name = 'ANCHOR_KOUNTER';
                    var dc = document.cookie;
                    var prefix = name + "=";
                    var begin = dc.indexOf("; " + prefix);
                    if (begin == -1) {
                    begin = dc.indexOf(prefix);
                    if (begin != 0) return null;
                    } else
                    begin += 2;
                    var end = document.cookie.indexOf(";", begin);
                    if (end == -1)
                    end = dc.length;
                    var new_kount = unescape(dc.substring(begin + prefix.length, end)) - 0 + 1;
                    document.cookie = "ANCHOR_KOUNTER="+new_kount;
                    window.document.myform.kount.value=new_kount; //take out this line if you delete the <form>
                    }

                    function initializeKounter() {
                    var name = 'ANCHOR_KOUNTER';
                    var dc = document.cookie;
                    var prefix = name + "=";
                    var begin = dc.indexOf("; " + prefix);
                    if (begin == -1) {
                    begin = dc.indexOf(prefix);
                    if (begin != 0) return null;
                    } else
                    begin += 2;
                    var end = document.cookie.indexOf(";", begin);
                    if (end == -1)
                    end = dc.length;
                    var curr_kount = unescape(dc.substring(begin + prefix.length, end));
                    window.document.myform.kount.value=curr_kount;
                    }
                    </script>
                    </head>

                    <body onload="initializeKounter();">
                    <form name="myform">
                    javascript cookie count: <input type="text" name="kount" size="5">
                    </form>

                    <a href="##boo" onclick="updateCookie()">click to goto anchor</a>
                    <table height=200>
                    <tr>
                    <td>words
                    </td>
                    </tr>
                    </table>

                    <a name="##boo">anchor</a>



                    </body>
                    </html>
                    • 7. Re: Track anchor clicks
                      etman Level 1
                      I'll have to check this out. If it works as well as I think I owe you two beers