Setting a URL parameter within Javasript

C

Charles

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
 
V

Vincent van Beveren

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.

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.referrer) {
s = document.referrer;
// take off http://
s = (s.indexOf("http://")==0?s.substring(7):s);
// take off www.
s = (s.indexOf("www.")==0?s.substring(4):s);
// take off everything beind the /
s = (s.indexOf("/")>=0?s.substring(0,s.indexOf("/")):s);
// take off everything beind the ?
s = (s.indexOf("/")>=0?s.substring(0,s.indexOf("?")):s);
// take off everything beind the #
s = (s.indexOf("/")>=0?s.substring(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
 
C

Charles

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.
 
V

Vincent van Beveren

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

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

There is one other solution, doing the following:

<HTML>
<BODY onLoad="document.getElementById('forward').submit();">
<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?
I also do not have access to the PHP code as it is provided by a
third party.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top