Tracking page visits

Discussion in 'Javascript' started by Terry, Jan 5, 2008.

  1. Terry

    Terry Guest

    Hi folks.

    I was thinking about rolling my own anlaytics service for sites that I
    am working on.
    I had the idea of using javacript to find all the links on a page and
    then attach handlers to them that would have code that would visit
    another site that has a database to keep track of hits and duration of
    stay at a particular page.

    I was wondering if it is possible to visit a site in the background so
    that the user goes to the page contained whose url is that of the href
    and not the site which will track the visit.

    So for example lets say that I have:

    <a href="http://www.mysite.com/page1.htm>Page 1</a>

    I am hoping that I can write some javascript that will see this link
    and attach code to it so that when the link is clicked Page 1 is
    accessed as well as its visit is recorded in my tracking service.

    So I was hoping my javacript would look through the dom see the link
    (<a href..) and attach the function tracker to it (i.e using
    addEventListener or attachEvent).

    function tracker()
    {
    //goto http://mytracker.com/track.asp?page=page1.htm
    //goto http://www.mysite.com/page1.htm
    }

    I suppose that I could use location.href or perhaps location.replace
    but I thought there might be a better way so that is why I posted
    here.

    Thanks,
    Terry
     
    Terry, Jan 5, 2008
    #1
    1. Advertising

  2. Terry wrote:
    > [...]
    > I was wondering if it is possible to visit a site in the background so
    > that the user goes to the page contained whose url is that of the href
    > and not the site which will track the visit.


    Users will absolutely *love* that. NOT.

    > So for example lets say that I have:
    >
    > <a href="http://www.mysite.com/page1.htm>Page 1</a>
    >
    > I am hoping that I can write some javascript that will see this link


    There is no link so far.

    > [...]
    > So I was hoping my javacript would look through the dom see the link
    > (<a href..) and attach the function tracker to it (i.e using
    > addEventListener or attachEvent).


    What about users without the required support?

    > [...]
    > I suppose that I could use location.href or perhaps location.replace
    > but I thought there might be a better way so that is why I posted
    > here.


    Use software that evaluates the server access log instead.


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Jan 5, 2008
    #2
    1. Advertising

  3. Terry

    Terry Guest

    On Jan 5, 3:36 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > Terry wrote:
    > > [...]
    > > I was wondering if it is possible to visit a site in the background so
    > > that the user goes to the page contained whose url is that of the href
    > > and not the site which will track the visit.

    >
    > Users will absolutely *love* that.  NOT.
    >
    > > So for example lets say that I have:

    >
    > > <a href="http://www.mysite.com/page1.htm>Page 1</a>

    >
    > > I am hoping that I can write some javascript that will see this link

    >
    > There is no link so far.


    I see my error in my link I was missing a quotation mark (").

    >
    > > [...]
    > > So I was hoping my javacript would look through the dom see the link
    > > (<a href..) and attach the function tracker to it (i.e using
    > > addEventListener or attachEvent).

    >
    > What about users without the required support?


    By required support do you mean not having javascript enabled?
    If that is the case, I would certainly hope that they would because
    that can could create a bit of
    a problem.

    >
    > > [...]
    > > I suppose that I could use location.href or perhaps location.replace
    > > but I thought there might be a better way so that is why I posted
    > > here.

    >
    > Use software that evaluates the server access log instead.
    >
    > PointedEars


    I thought that it would be an interesting exercise to see if I could
    do it.
    Is that not what Google-Analytics is doing for sites that request it's
    service.

    Anyways, I was wondering is it possible to visit a site in the
    background so I don't have to mess around with location.href or
    perhaps location.replace.

    Are you aware of a way to do that?

    Thanks again,
    Terry
     
    Terry, Jan 5, 2008
    #3
  4. Terry wrote:
    > [...] Thomas 'PointedEars' Lahn [...] wrote:
    >> Terry wrote:
    >>> [...] So I was hoping my javacript would look through the dom see the
    >>> link (<a href..) and attach the function tracker to it (i.e using
    >>> addEventListener or attachEvent).

    >> What about users without the required support?

    >
    > By required support do you mean not having javascript enabled?


    For this to work, any ECMAScript implementation and sufficient DOM support
    would be required.

    > If that is the case, I would certainly hope that they would because that
    > can could create a bit of a problem.


    ISTM that I pointed out this major flaw in your design decisions before.

    >>> [...] I suppose that I could use location.href or perhaps
    >>> location.replace but I thought there might be a better way so that is
    >>> why I posted here.

    >> Use software that evaluates the server access log instead. [...]

    >
    > I thought that it would be an interesting exercise to see if I could do
    > it. Is that not what Google-Analytics is doing for sites that request
    > it's service.


    Google Analytics is the result of a misguided approach, which is why the
    data collected with it is not representative; it can not be.

    > Anyways, I was wondering is it possible to visit a site in the background
    > so I don't have to mess around with location.href or perhaps
    > location.replace.
    >
    > Are you aware of a way to do that?


    If you abandon the aforementioned unreliable approach, you will have to use
    a server-side script and the `Location' HTTP header, or URL rewrite. AFAIK,
    only the former could involve server-side J(ava)Script.


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Jan 5, 2008
    #4
  5. Terry

    El Kabong Guest

    "Thomas 'PointedEars' Lahn" <> wrote in message
    news:...
    > Terry wrote:
    >
    > Google Analytics is the result of a misguided approach, which is why the
    > data collected with it is not representative; it can not be.


    Please explain.

    El
     
    El Kabong, Jan 5, 2008
    #5
  6. El Kabong wrote:
    > "Thomas 'PointedEars' Lahn" [...]:
    >> Google Analytics is the result of a misguided approach, which is why the
    >> data collected with it is not representative; it can not be.

    >
    > Please explain.


    Google Analytics does not work without client-side script support, which
    is why those hits are not registered. However, there can be a number of
    reasons why that support would not be available; it being disabled by the
    user is only one of them.


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Jan 5, 2008
    #6
  7. Terry

    Terry Guest

    On Jan 5, 5:00 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > El Kabong wrote:
    > > "Thomas 'PointedEars' Lahn" [...]:
    > >> Google Analytics is the result of a misguided approach, which is why the
    > >> data collected with it is not representative; it can not be.

    >
    > > Please explain.

    >
    > Google Analytics does not work without client-side script support, which
    > is why those hits are not registered.  However, there can be a number of
    > reasons why that support would not be available; it being disabled by the
    > user is only one of them.
    >
    > PointedEars
    > --
    > Use any version of Microsoft Frontpage to create your site.
    > (This won't prevent people from viewing your source, but no one
    > will want to steal it.)
    >   -- from <http://www.vortex-webdesign.com/help/hidesource.htm>


    Thanks again for responding to my post. I am new to this game and am
    truly enjoying it. I have learned alot here and in particular from
    you.

    I was wondering how is server-side javascript implemented. I have only
    seen javascript used on the server when used as the scripting language
    within classic asp.

    I am assuming that server side javascript will not be apparent to the
    user. Perhaps, it might a value in a database.

    Thanks,
    Terry
     
    Terry, Jan 6, 2008
    #7
  8. Terry wrote:
    > [...] Thomas 'PointedEars' Lahn [...] wrote:
    >> El Kabong wrote:
    >>> "Thomas 'PointedEars' Lahn" [...]:
    >>>> Google Analytics is the result of a misguided approach, which is why the
    >>>> data collected with it is not representative; it can not be.
    >>> Please explain.

    >> Google Analytics does not work without client-side script support, which
    >> is why those hits are not registered. However, there can be a number of
    >> reasons why that support would not be available; it being disabled by the
    >> user is only one of them.
    >> [...]


    Please trim your quotes. Especially, don't quote signatures unless you
    directly refer to them.

    http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1Trim

    > [...]
    > I was wondering how is server-side javascript implemented. I have only
    > seen javascript used on the server when used as the scripting language
    > within classic asp.


    I know only two applications of server-side ECMAScript implementations; one
    is JScript (.NET) in Microsoft ActiveServer Pages (ASP) (.NET) with Internet
    Information Services (IIS), the other is Server-Side JavaScript with a
    Netscape Enterprise Server (NES)-compatible Web server (such as the Sun Java
    System Web Server, I suppose). The Wikipedia lists more applications:

    http://en.wikipedia.org/wiki/Server-side_JavaScript

    > I am assuming that server side javascript will not be apparent to the
    > user.


    You are correct.

    > Perhaps, it might a value in a database.


    It might use an existing database connection.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Jan 6, 2008
    #8
  9. On Sat, 05 Jan 2008 12:50:24 -0800, Terry wrote:

    > By required support do you mean not having javascript enabled? If that
    > is the case, I would certainly hope that they would because that can
    > could create a bit of
    > a problem.


    Ouch!

    Always plan on what will happen should Javascript not be available.
     
    Jeremy J Starcher, Jan 8, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alberto

    count visits

    Alberto, Oct 30, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    585
    Scott M.
    Oct 30, 2003
  2. K.
    Replies:
    4
    Views:
    391
  3. fulio pen
    Replies:
    9
    Views:
    475
    William Gill
    Sep 28, 2007
  4. Steve

    Page Visits

    Steve, Nov 13, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    420
    Hillbilly
    Nov 14, 2008
  5. goks
    Replies:
    7
    Views:
    305
    Thomas 'PointedEars' Lahn
    May 30, 2004
Loading...

Share This Page