+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16

 

Thread: Converted Keyword Tracking using PHP - How?

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts


    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

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Gillingham
    Posts
    510
    Thanks
    0
    Thanked 4 Times in 1 Post
    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

  3. #3
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    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:

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['tracking'] = $_GET['parameter_name'];
    ?>
    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(); ?>
    You now need to deal with putting the parameter in the session variable into your affiliate link.

    At the very simplest level you would then just insert the keyword into the link from the session as the Donk said.

    PHP Code:
    http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $_SESSION['tracking'];?>
    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 eg

    Code:
    http://www.mysite.com/tracking.php?link_id=1
    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 eg

    Code:
    http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=[clickref]
    You can then use the str_replace command to replace this with the actual tracking id from the session and then redirect:

    PHP Code:
    $new_link str_replace("[clickref]",$_SESSION['tracking'],$link_from_database);
    header("Location: " $new_link); 
    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.

  4. #4
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Donk & tbp,

    Great response! This is what I am looking for :tup Thanks again

  5. #5
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['tracking'] = $_GET['kw'];
    $_SESSION['tracking'] = $_GET['OVKEY'];
    ?>
    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:
    <?
    header
    ("Location: http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $_SESSION['tracking'];?>");
    ?>
    Am I right to put the following session start code:
    PHP Code:
    <?php session_start(); ?>
    in each of my affiliate file ONLY in order to activate the session but NOT from the page before directing over to this page.

    I am sorry to ask stupid question, just want to ensure :blush

  6. #6
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    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:

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['search'] = $_GET['search'];
    $_SESSION['keyword'] = $_GET['keyword'];
    ?>
    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.

    Your affiliate link in principle is basically fine eg

    PHP Code:
    <? 
    header
    ("Location: http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=<?php echo $_SESSION['tracking'];?>"); 
    ?>
    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.

    If you were sending over 2 parameters, you would want them both in the affiliate link eg

    PHP Code:
    <? 
    $click_ref 
    $_SESSION['search'] . "-" $_SESSION['keyword'];
    header("Location: http://www.awin1.com/awclick.php?mid=3&id=45628&clickref=" $click_ref); 
    ?>
    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.

  7. #7
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['kw'] = $_GET['kw'];
    $_SESSION['OVKEY'] = $_GET['OVKEY'];
    ?>
    2) Then in my affiliate link

    HTML Code:
    http://www.awin1.com/awclick.php?mid=1&id=12345&clickref=<?php echo $_SESSION['kw'];?>
    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"

    3) Should I use the following codes instead of above to echo two parameter?

    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;?>
    What should I do? I am feeling slightly confused in the meantime.....

  8. #8
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    Actually very easy to do both parameters. Instead of having:

    PHP Code:
    clickref=<?php echo $_SESSION['kw'];?>
    in the link, just change it to:

    PHP Code:
    clickref=<?php echo $_SESSION['kw'] . "-" $_SESSION['OVKEY'] ;?>
    This will display the two values with a hyphen in between.

  9. #9
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    clickref=<?php echo $_SESSION['kw'] . "-" $_SESSION['OVKEY'] ;?>
    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:
    <?php
    session_start
    ();
    $_SESSION['track'] = $_GET['kw'];
    $_SESSION['track'] = $_GET['OVKEY'];
    ?>
    and then

    PHP Code:
    clickref=<?php echo $_SESSION['track'];?>
    $_SESSION['track'] to track both traffic source from google and yahoo or msn. Can I use similar variable name for SESSION in this case?

    :blush

  10. #10
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    Ahh, sorry, misunderstood what you want to do.

    You need to do the following:

    PHP Code:
    <?php
    sessions_start
    ();
    if(
    strlen($_GET['kw']) > 0){
      
    $_SESSION['track'] = $_GET['kw'];
    } elseif(
    strlen($_GET['OVKEY']) > 0) {
      
    $_SESSION['track'] = $_GET['OVKEY'];
    }
    ?>
    That will set $_SESSION['track'] to which ever one has value, and then you just use $_SESSION['track'] in your link as normal eg

    PHP Code:
    clickref=<?php echo $_SESSION['track'];?>
    Just a quick note so that you know, the following wouldn't work:

    PHP Code:
    <?php 
    session_start
    (); 
    $_SESSION['track'] = $_GET['kw']; 
    $_SESSION['track'] = $_GET['OVKEY']; 
    ?>
    The reason being is that if $_GET['kw'] had a value, then $_SESSION['track'] would be set to this.

    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.

  11. #11
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  12. #12
    Registered User

    Status
    Offline
    Join Date
    Jan 2008
    Location
    Yorkshire
    Posts
    536
    Thanks
    22
    Thanked 37 Times in 31 Posts
    Quote Originally Posted by internet-laptop View Post
    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?
    Make sure that you put the "session_start" code before anything else

  13. #13
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I put my session_start code on top of <html> tag, such as shown below:

    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>
    Am I still missing something else?

  14. #14
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    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>

  15. #15
    Registered User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks tbp,

    Yes it finally worked......:tup

    Is my mistake, I totally misunderstood the placement of session_start()......:blush part of my learning process

+ Reply to Thread
Page 1 of 2 1 2 LastLast


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Passing Keyword Data Thru php Redirect Links?
    By KirstyM in forum Programming
    Replies: 1
    Last Post: 23-04-08, 10:56 AM
  2. Keyword Tracking - EPI & SID
    By m-a-hudson in forum Programming
    Replies: 2
    Last Post: 20-12-05, 03:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2