EDITED TO INCLUDE Rich's Pointers
(thanks Rich)
Javascript version:
Set the cookie (this part goes accross all your product pages in a .tpl file or global include)
you can dump the lot in a single js include file and just add
Code:
<script type="text/JavaScript" language="JavaScript" src="/network.js"> </script>
** the above asumes you named your js file network.js and it sits in the same dir
Code:
<script language="javascript">
function setCookie(name, value, expires, path, domain, secure) {
var thisCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = thisCookie;
}
function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; }
}
function queryString(key){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));
}
function displayItem(key){
if(queryString(key)=='false')
{
// THE QUERYSTRING IS NOT AFF SO COOKIE NOT SET //
}else if(queryString(key) != 'af' && queryString(key) != 'aw'){
// AFF DOES NOT = af or aw (OUR NETWORKS) NO COOKIE SET //
}else{
// QUERYSTRING DOES = af or aw OUR NETWORKS SO COOKIE SET //
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000*365)); // change last number for number of days you want the cookie to live.
setCookie('network',queryString(key),expdate)
}
}
if(window.location.search.substring(1) != ''){
displayItem('aff')
}
</script>
important parts of the code explained:
displayItem('aff')
aff is the substring (querystring) we are looking for i.e aff=VALUE
Code:
}else if(queryString(key) != 'af' && queryString(key) != 'aw'){
this disregards anything that does not = the networks we are looking for i.e af (our code for affiliate future ) and aw (our code for affiliate window)
to add other networks you would simply alter the above so lets say we have affiliate window, affiliate future and web gains ( have been into webgains and set aff=wg as you custom values to append your querystrings * ask webgains how this is done)
our code will now look like this:
Code:
}else if(queryString(key) != 'af' && queryString(key) != 'aw' && queryString(key) != 'wg'){
Now lets take a look at the code to trigger the correct network after checkout and destroy our local cookie.
this code goes where your network code goes on the end of your checkout.
we will be using our standard example of af and aw as above then show you how to modify it to include others.
Code:
<script language="javascript">
function getcookie(cookiename) {
var cookiestring=""+document.cookie;
var index1=cookiestring.indexOf(cookiename);
if (index1==-1 || cookiename=="") return "";
var index2=cookiestring.indexOf(';',index1);
if (index2==-1) index2=cookiestring.length;
return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
if(getcookie('network') == 'af'){
// Affiliate FUTURE CODE GOES HERE !!!! ??? >> //
}else if(getcookie('network') == 'aw'){
// Affiliate WINDOW CODE GOES HERE !!!! ??? >> //
}else{
// NO COOKIE SO USER DID NOT COME FROM A NETWORK //
// ALL NETWORKS CODE HERE INCASE WE MISSED //
}
// DONT KILL OUR COOKIE
</script>
<noscript>
<!--//
Mod by Rich ALL networks here
//-->
</noscript>
As with the above example lets say we have added Webgains as aff=wg we would add
Code:
}else if(getcookie('network') == 'wg'){
// WEBGAINS CODE HERE ?? >> //
this would be placed under or above:
Code:
}else if(getcookie('network') == 'aw'){
// Affiliate WINDOW CODE GOES HERE !!!! ??? >> //
I have started with the javasctript one as it is the most difficult with asp and php it is far simpler to request querystrings, request cookies and set them. But the great advantage is it will work with html pages good news if you are ussing mod_rewrite for your SEO. Most of the functions used in the above code widley available on the net if you want to go it alone do a google "javascript FunctionName.
Quick Note:
Cookies can only be read by the domain that set them ** this will require extra programming to work if your check out is on your main site but your products are on a sub domain or vice versa. And will not work if the 2 are hosted on seprerate sites.
Stay tuned for the ASP and PHP versions and a smarty one for your checkout pages (.tpl)
You will of course be able to mix and match javascript & php & smarty PHP & ASP accross your products and end of checkout pages.
I will help freely to install this soloution if anyone needs and you can drop some into the wifes ebay fund if you so wish.
Enjoy.
Bookmarks