473,465 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Jul 23 '05 #1
3 7293
> 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

Jul 23 '05 #2
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" <vi*****@provident.remove.this.nl> wrote in message
news:40***********************@news.xs4all.nl...
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

Jul 23 '05 #3
> 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.

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bruno | last post by:
Hello, first of all, I hope I access the right newsgroup. I am creating a dial-up-network within a eVC++ 4.0 program. This network uses a modem connected to a mobile device via a serial cable....
8
by: Tony Johansson | last post by:
Hello Experts! What does this mean actually. If you have a template with a type and non-type template argument, say, like this template<typename T, int a> class Array {. . .}; then A<int,...
0
by: Rhino | last post by:
I am working with SQL Functions in DB2 for Windows/Linux/UNIX (V8.2.1) and am having a problem setting input parameters for SQL Functions to null in the Development Center. My simple function,...
2
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among...
0
by: Billie Boy | last post by:
Hi to all. I’m new here and am coming to you from Melbourne Australia. So a big HELLO 2 ALL. Now I am encountering an annoying problem in the SQL builder of the copy of VB.6 that I am using at...
4
by: BrianKE | last post by:
I am attempting to create an app that will run "on top" of another app. My app will create a transparent window over the other app for the purpose of displaying information. I am able to create...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: AshuPd | last post by:
Hi all !!! I am fighting with a very interesting issue... What i need is to link a javasript with a imagebutton control which is already on a datalist. the problem is, if i place the control out...
1
by: Mike P | last post by:
I am adding a hyperlink to a table and I want the hyperlink to open a window with height and width I can set myself when it is clicked : HyperLink hypGetExtractSQL = new HyperLink(); ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.