Setting a URL parameter within Javasript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles

    Setting a URL parameter within Javasript

    I use URL parameters to track the source of a click and track Pay-Per-Click
    results. For example, if a click originates from Google AdWords, the URL is
    www.mysite.com/?source=google. For Google this works fine, but for many
    other Pay-Per-Click search engines, the URL parameter seems to get lost and
    the user gets directed to www.msysite.com.

    Let's call the search engine for which this does not work "dummy". I was
    thinking about sending users directly to www.mysite.com/dummy.html, and
    within dummy.html I would set the parameter within a JavaScript to what
    "dummy", using this command: var source = "dummy".

    This does not seem to work, the php program that is executed later within
    the JavaScript does not correctly interpreted the source variable and
    therefore does not register a click from search engine "dummy". So, the
    question is, how can I set the source variable within the HTML if it has not
    been passed as part of the URL.

    Thanks.
    Charles


  • Vincent van Beveren

    #2
    Re: Setting a URL parameter within Javasript

    > This does not seem to work, the php program that is executed later within[color=blue]
    > the JavaScript does not correctly interpreted the source variable and
    > therefore does not register a click from search engine "dummy". So, the
    > question is, how can I set the source variable within the HTML if it has not
    > been passed as part of the URL.[/color]

    Is it not possible to do the following on the dummy.html page:

    location.href="/?source=dummy";

    What you can also do ofcourse is the following when PHP detects that
    source is empty write the following script:

    // is there a referrer url?
    if (document.refer rer) {
    s = document.referr er;
    // take off http://
    s = (s.indexOf("htt p://")==0?s.substri ng(7):s);
    // take off www.
    s = (s.indexOf("www .")==0?s.substr ing(4):s);
    // take off everything beind the /
    s = (s.indexOf("/")>=0?s.substri ng(0,s.indexOf( "/")):s);
    // take off everything beind the ?
    s = (s.indexOf("/")>=0?s.substri ng(0,s.indexOf( "?")):s);
    // take off everything beind the #
    s = (s.indexOf("/")>=0?s.substri ng(0,s.indexOf( "#")):s);
    // take off last .com .net or whatever
    s = (s.lastIndexOf( ".")>=0?
    s.substring(0,s .lastIndexOf(". ")):s);
    // check wether its not from yourself
    if (s!='mysite') {
    // refresh page with found source
    location = "/?source="+s;
    }
    }

    Good luck,
    Vincent

    Comment

    • Charles

      #3
      Re: Setting a URL parameter within Javasript

      I have tried using location.href="/?source=dummy"; in the Java Scipt, but
      that results in the browser being closed. I also do not have access to the
      PHP code as it is provided by a third party.


      "Vincent van Beveren" <vincent@provid ent.remove.this .nl> wrote in message
      news:40fb9580$0 $14941$e4fe514c @news.xs4all.nl ...[color=blue][color=green]
      > > This does not seem to work, the php program that is executed later[/color][/color]
      within[color=blue][color=green]
      > > the JavaScript does not correctly interpreted the source variable and
      > > therefore does not register a click from search engine "dummy". So, the
      > > question is, how can I set the source variable within the HTML if it has[/color][/color]
      not[color=blue][color=green]
      > > been passed as part of the URL.[/color]
      >
      > Is it not possible to do the following on the dummy.html page:
      >
      > location.href="/?source=dummy";
      >
      > What you can also do ofcourse is the following when PHP detects that
      > source is empty write the following script:
      >
      > // is there a referrer url?
      > if (document.refer rer) {
      > s = document.referr er;
      > // take off http://
      > s = (s.indexOf("htt p://")==0?s.substri ng(7):s);
      > // take off www.
      > s = (s.indexOf("www .")==0?s.substr ing(4):s);
      > // take off everything beind the /
      > s = (s.indexOf("/")>=0?s.substri ng(0,s.indexOf( "/")):s);
      > // take off everything beind the ?
      > s = (s.indexOf("/")>=0?s.substri ng(0,s.indexOf( "?")):s);
      > // take off everything beind the #
      > s = (s.indexOf("/")>=0?s.substri ng(0,s.indexOf( "#")):s);
      > // take off last .com .net or whatever
      > s = (s.lastIndexOf( ".")>=0?
      > s.substring(0,s .lastIndexOf(". ")):s);
      > // check wether its not from yourself
      > if (s!='mysite') {
      > // refresh page with found source
      > location = "/?source="+s;
      > }
      > }
      >
      > Good luck,
      > Vincent
      >[/color]


      Comment

      • Vincent van Beveren

        #4
        Re: Setting a URL parameter within Javasript

        > I have tried using location.href="/?source=dummy"; in the Java Scipt,[color=blue]
        > but that results in the browser being closed.[/color]

        Thats strange. Is there an example I can try? That really should work.

        There is one other solution, doing the following:

        <HTML>
        <BODY onLoad="documen t.getElementByI d('forward').su bmit();">
        <FORM METHOD="GET" ACTION="/" ID="forward">
        <HIDDEN NAME="source" VALUE="somesite ">
        </FORM>
        </BODY>
        </HTML>

        You could combine it with the referrer script to make it work
        universally. If that doesn't work something else is probably wrong that
        is preventing the script from running properly. Have you tried it on
        other computers?
        [color=blue]
        > I also do not have access to the PHP code as it is provided by a
        > third party.[/color]

        Oh, well, in that case the referrer trick would make life easier even if
        it is in the dummy page. So, you could name it searchhook.html and pass
        on the referrer as the source.

        Comment

        Working...