Try
PHP Code:<?php
if ($_GET['kw']) $keyword =$_GET['kw'];
if ($_GET['OVKEY']) $keyword =$_GET['OVKEY'];
etc
?>
http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $keyword;?>
Hi,
I want to use php to track my converted keywords from ppc. I have no/limited knowledge of php language. Can anyone help?
Below is my situation:
I am using google and yahoo ppc. When the clicks into my landing page, I want to pass the keyword to the landing page/site and then from that page would need to capture the keyword and pass it in to all my "Affiliate Window" affiliate links contained on the page and any subsequent pages.
The tracking URL for my google and yahoo are as follow:
Google = http://www.site.com/?kw=keyword
Yahoo = http://www.site.com/?OVRAW=keyword&OVKEY=keyword&...etc
I want to use PHP to code the page to take the keyword from the tracking url above and pass it in to the affiliate link below:
http://www.awin1.com/awclick.php?mid=3&id=45628&clickref={keyword}
Does anyone know how do I do it? thanks
![]()
Try
PHP Code:<?php
if ($_GET['kw']) $keyword =$_GET['kw'];
if ($_GET['OVKEY']) $keyword =$_GET['OVKEY'];
etc
?>
http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $keyword;?>
They came for my 404 and I said nothing
It's actually pretty easy to do.
To start in your adwords ad, add an extra parameter to the landing page url, which will tell you that the click came from adwords, and from a certain keyword for example. I tend to encode these, for example number 1 would represent adwords and a certain campaign.
On your landing page, read the parameter from the URL using $_GET['parameter_name'], and put it in a session or cookie, which will temporarily save it. To do this with a session, add the following code to the very top (above the html) of your landing page:
On any page that you want to work with the session parameter, make sure that you add the following to the first line of the code, to activate session variables for that page:PHP Code:<?php
session_start();
$_SESSION['tracking'] = $_GET['parameter_name'];
?>
You now need to deal with putting the parameter in the session variable into your affiliate link.PHP Code:<?php session_start(); ?>
At the very simplest level you would then just insert the keyword into the link from the session as the Donk said.
For a more advanced setup, you would store your links in a database, and all your affiliate links would go to a certain page on your site - rather than straight to the network egPHP Code:http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $_SESSION['tracking'];?>
On tracking.php, you would read the link from the database that has the id of 1. In your database you would store the url with a token in the click ref parameter egCode:http://www.mysite.com/tracking.php?link_id=1
You can then use the str_replace command to replace this with the actual tracking id from the session and then redirect:Code:http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=[clickref]
However, before you redirect you can update the click count for that link, giving you your own stats as to how many times a link has been clicked. This is useful as on your site you can see the number of people who clicked on a product to go to the merchants site, even if the person didn't decide to but that product. You could then move the most clicked products to the front page of your site for example.PHP Code:$new_link = str_replace("[clickref]",$_SESSION['tracking'],$link_from_database);
header("Location: " . $new_link);
Thanks Donk & tbp,
Great response! This is what I am looking for :tup Thanks again![]()
Hi,
I got some few questions:
1) As I am running both google and yahoo ppc, am I right to add the following session code on top of my landing page?
2) For all my affiliate link, I am using php redirect method to hide my affiliate URL. For instance, if let said "tracking.php" is my affiliate link file with the following code to redirect to network/merchant:PHP Code:<?php
session_start();
$_SESSION['tracking'] = $_GET['kw'];
$_SESSION['tracking'] = $_GET['OVKEY'];
?>
Am I right to put the following session start code:PHP Code:<?
header("Location: http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $_SESSION['tracking'];?>");
?>
in each of my affiliate file ONLY in order to activate the session but NOT from the page before directing over to this page.PHP Code:<?php session_start(); ?>
I am sorry to ask stupid question, just want to ensure :blush
Basically, the code you add to the landing page depends on the url parameters you are sending over from your PPC ads.
For instance, in google, say your landing page url was:
http://www.mysite.com/landing_page.p...word=mykeyword
Then on the top of your landing page you would use:
This would capture the variable you are sending over and put them in session variables, so they are available on any page of your site.PHP Code:<?php
session_start();
$_SESSION['search'] = $_GET['search'];
$_SESSION['keyword'] = $_GET['keyword'];
?>
Your affiliate link in principle is basically fine eg
However, in here you have PHP tags inside of PHP tags, so it wouldn't work. You don't need the inner set of PHP tags, as you are already inside a block of PHP.PHP Code:<?
header("Location: http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $_SESSION['tracking'];?>");
?>
If you were sending over 2 parameters, you would want them both in the affiliate link eg
With the session_start(), you basically need to put it on any page where you read or write session variables, as it enables session variables on that page. You can be safe and put in on every page of your site if you want, in a common header file for example. It doesn't matter if its there on pages where you don't use sessions.PHP Code:<?
$click_ref = $_SESSION['search'] . "-" . $_SESSION['keyword'];
header("Location: http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=" . $click_ref);
?>
After numerous failure attempts of trying to hide my affiliate link using php redirect, I decided to adapt the simplest approach, that is using straight affiliate link. I got the following questions with this simplest approach:
Let said my PPC tracking URL as follows:
Google: http://www.abc.com/?kw=keywords
Yahoo: http://www.abc.com/?OVRAW=keywords&O...eywords&...etc
1) I done as what tbp suggested using session, and I put the following codes at top of my landing page above <html> tag:
2) Then in my affiliate linkPHP Code:<?php
session_start();
$_SESSION['kw'] = $_GET['kw'];
$_SESSION['OVKEY'] = $_GET['OVKEY'];
?>
As you can see above, it only echo one parameter, i.e. kw, my question is how do I echo two parameter in one single affiliate link? I want to echo "kw" and "OVKEY"HTML Code:http://www.awin1.com/awclick.php?mid=1&id=12345&clickref=<?php echo $_SESSION['kw'];?>
3) Should I use the following codes instead of above to echo two parameter?
What should I do? I am feeling slightly confused in the meantime.....PHP Code:<?php
if ($_GET['kw']) $keyword =$_GET['kw'];
if ($_GET['OVKEY']) $keyword =$_GET['OVKEY'];
etc
?>
http://www.awin1.com/awclick.php?mid=3&id=12345&clickref=<?php echo $keyword;?>![]()
Actually very easy to do both parameters. Instead of having:
in the link, just change it to:PHP Code:clickref=<?php echo $_SESSION['kw'];?>
This will display the two values with a hyphen in between.PHP Code:clickref=<?php echo $_SESSION['kw'] . "-" . $_SESSION['OVKEY'] ;?>
Thanks TBP :tup
I want to know whether it make any different, as both 'kw' and 'OVKEY' parameter were coming from different sources, one from google and another from yahoo. I believed that by using this codes:
it will echo something like clickref= -honey from Yahoo traffic, and clickref=honey- from google traffic. Am I right to assumed that? or can I use something like this:PHP Code:clickref=<?php echo $_SESSION['kw'] . "-" . $_SESSION['OVKEY'] ;?>
and thenPHP Code:<?php
session_start();
$_SESSION['track'] = $_GET['kw'];
$_SESSION['track'] = $_GET['OVKEY'];
?>
$_SESSION['track'] to track both traffic source from google and yahoo or msn. Can I use similar variable name for SESSION in this case?PHP Code:clickref=<?php echo $_SESSION['track'];?>
:blush
Ahh, sorry, misunderstood what you want to do.
You need to do the following:
That will set $_SESSION['track'] to which ever one has value, and then you just use $_SESSION['track'] in your link as normal egPHP Code:<?php
sessions_start();
if(strlen($_GET['kw']) > 0){
$_SESSION['track'] = $_GET['kw'];
} elseif(strlen($_GET['OVKEY']) > 0) {
$_SESSION['track'] = $_GET['OVKEY'];
}
?>
Just a quick note so that you know, the following wouldn't work:PHP Code:clickref=<?php echo $_SESSION['track'];?>
The reason being is that if $_GET['kw'] had a value, then $_SESSION['track'] would be set to this.PHP Code:<?php
session_start();
$_SESSION['track'] = $_GET['kw'];
$_SESSION['track'] = $_GET['OVKEY'];
?>
However, on the next line, $_SESSION['track'] would be overwritten by $_GET['OVKEY']. If $_GET['OVKEY'] had no value, then $_SESSION['track'] would be set to nothing, rather than retaining the previous value.
Hi tbp,
I follow exactly as what you suggested. I got the following warning message when I tried to load the pages online:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/internp5/public_html/mywebsite/abc.php:2) in /home/internp5/public_html/mywebsite/abc.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/internp5/public_html/mywebsite/abc.php:2) in /home/internp5/public_html/mywebsite/abc.php on line 2
Is it something to be worry about? What exactly does it meant?
I put my session_start code on top of <html> tag, such as shown below:
Am I still missing something else?HTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php session_start(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
You need to put the session_start() command as the very first line on your page, before any HTML or other PHP.
The session_start() command modifies the web pages header to keep track of the session. Once any output has been sent to the browser, the page header is closed and cannot be reopened.
With you current code, the first HTML line is being sent to the browser, closing the page header. It then tries to access the header for the session_start() command, but because the header is closed its failing.
So you need to have:
Code:<?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
Thanks tbp,
Yes it finally worked......:tup
Is my mistake, I totally misunderstood the placement of session_start()......:blush part of my learning process![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks