1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Appending parameters to end of affiliate URLs

Discussion in 'PHP' started by grafx77, Jun 7, 2006.

  1. #1
    I am currently looking for a script that can append a parameter (keyword, medium, source) dynamically using cookies to the end of my CJ, Linkshare, and Performics affiliate links (sid=,mid=,u1=)

    It would be really nice, if it were possible to append a whole referring url to the end of the affiliate links. I am about to hunt down a few programmers on some of the freelance boards, but thought I would drop by and see if anyone knew how to do this and if there was a free script out there that would accomplish this feat.
     
    grafx77, Jun 7, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It depends how your site works and whether its database driven or not.

    Essentially you just add the links to the end of the url.

    <?php
    $url="http://www.affiliateurl.com/x=125235&ref_url=$PHP_SELF&sid=124556";
    
    echo"$url";
    ?>
    PHP:
     
    mad4, Jun 7, 2006 IP
  3. chengfu

    chengfu Well-Known Member

    Messages:
    113
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #3
    If you wanted to attach the complete referring url you could do something like this:
    
    <?php
    $url = 'http://www.affiliate.com/?id=12345&sid='.urlencode(getenv('HTTP_REFERER'));;
    ?>
    
    PHP:
     
    chengfu, Jun 7, 2006 IP
  4. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Ok, Im not a programmer so please explain to me how this would work. Do I copy and paste the code, as is, into a .php page wherever I want my affiliate link posted? What about the set cookie? How does this code call the information from that?

    I need a bit more insight and information than this please.
     
    grafx77, Jun 7, 2006 IP
  5. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Maybe if you explain exactly what you are trying to do (and why) along with some details of how your site works we can help more.
     
    mad4, Jun 7, 2006 IP
  6. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Ok....I'll give it a try.

    I would like the a parameter that I can setup within my tracking urls to be appended to the end of my affiliate urls. Are you familiar with the shopper IDs for CJ, linkshare, and performics? They basically look like this.......www.mycjaffiliatelink.com?sid= . I would need a parameter dynamically appended to the end of this. Example located below:

    Once the visitor hovers over or clicks my affiliate link, the stored parameter would be appended to the end of the link.

    Example: www.mycjaffiliatelink.com?sid=
    My tracking link- www.mydomain.com?t=12&p=online+gaming
    Once the visitor clicks on my tracking link, my affiliate link would look like this- www.cjaffiliatelink.com?sid=online+gaming

    I would like the visitor to be able to browse around my site and even leave and come back to my site and still have this value contained within the cookie. For the above example...that value would be online gaming.

    If there is the ability to do so, I would like entire referring urls to be appended as well, so I can track referring urls to affiliate sales. I'm not sure if this can be done though, but it would be most helpful as an addition to the passed parameters on my tracking links.

    Hopefully this clears things up a bit.
     
    grafx77, Jun 7, 2006 IP
  7. asr_guy

    asr_guy Peon

    Messages:
    178
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It doesn't sound like it would take much effort:
    -check referring url
    -stick it into a cookie on your visitor
    -when visitor hits any of your referral links on your site append the url (or maybe a coded id number that you translate back later) and send them off
    -check the merchant reports for sales by referring url/id

    This sounds like a custom job, but probably there's some demand for this from the affiliate community - especially from affiliates who are into web analytics and optimizing their "sales" when the sales are downstream.

    But I can't believe there's nothing like this already. Check with the CJ forum on abestweb - maybe there's some people there who can help.

    Cheers,
    Peter
     
    asr_guy, Jun 7, 2006 IP
  8. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is what I use if someone hits a landing page from a PPC click... the PPC url is like

    http://www.example.com/coupon.php?sid=ADC-{keyword}

    if ($_REQUEST['sid'] AND !($_COOKIE['sid']))
    {
    	setcookie("sid",urlencode($_REQUEST['sid']),time()+(86400*365));
    	$_COOKIE['sid'] = $_REQUEST['sid'];
    }
    
    Code (markup):
    So it checks to see if a sid cookie is already set; if not, set a new one. Then on all of the CJ links on that site, you have

    $link = "www.dpbolvw.net/mg101esagesa3fg2fesaefeqqw321335BC?sid=".$_COOKIE['sid'];
    Code (markup):
     
    TheHoff, Jun 7, 2006 IP
  9. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #9
    Yeah....this is definately a custom job. I've checked many forums, including Abestweb and haven't found anything. I would think this type of script would be actively used and displayed over the net, but its not, and I think many affiliates aren't even aware of the capability of Shopper IDs from some of these affiliate networks.
    If anything, I'll search on elance or rentacoder and get someone to develop one for me that can work for anyone one of my sites.
     
    grafx77, Jun 8, 2006 IP
  10. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #10
    Thanks for the suggestion Hoff. This looks good in theory, but I can't quite understand what your relaying to me. If you have the time, could you please lay the above coding out into steps or details?

    For example:

    1.http://www.example.com/coupon.php?sid=ADC-{keyword} <--Is this URL your tracking url....and what goes in place of the keyword brackets, do you manually insert the keyword within the brackets or is the keyword dynamically inserted into the brackets once the visitors clicks on your ad? Adwords & MSN Adcenter use these brackets to insert keywords dynamically, thats why I ask.
    2. Does the "set cookie" code get placed on all entry pages?
    3. Is the "set cookie" code relevant as-is or do I have to modify it for my page?

    Please give me an example of exactly how you setup your PPC tracking for Shopper IDs. If need be, you can PM me or message me on MSN messager. I believe its in my profile.
     
    grafx77, Jun 8, 2006 IP
  11. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #11
    TheHoff has given pretty much what you need.

    I use Google Analytics to track all this stuff for me. Add a javascript onclick event to the affiliate links to track when people click on them.
     
    mad4, Jun 8, 2006 IP
  12. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #12
    I use Google Analytics myself to track onsite analytical and statistical information. The merchant would need a conversion code in order for Analytics to track it as a "goal".

    I am under the impression that a javascript onclick event triggers an alert or background colors and so forth, but is there a javascript code that appends a value from my tracking urls to the end of affiliate urls? If so, let me know. I would truly appreciate it. :D
     
    grafx77, Jun 8, 2006 IP
  13. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #13
    Is this the onclick javascript you are speaking of?

    <script>
    function addText(event){
    document.getElementById("box").value +=
    (event.srcElement || event.target).firstChild.nodeValue.toString();
    }
    </script>
    
    <input id="box">
    
    <table border=1 cellspacing=0 onclick=addText(event)>
    <tr><td>A</td><td>B</td><td>C</td></tr>
    <tr><td>D</td><td>E</td><td>F</td></tr>
    </table>
    
    Code (markup):
     
    grafx77, Jun 8, 2006 IP
  14. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #14
    >>1.http://www.example.com/coupon.php?sid=ADC-{keyword} <--Is this URL your tracking url....and what goes in place of the keyword brackets, do you manually insert the keyword within the brackets or is the keyword dynamically inserted into the brackets once the visitors clicks on your ad? Adwords & MSN Adcenter use these brackets to insert keywords dynamically, thats why I ask.

    Right, that is the URL I would put into my ad on Adcenter. When visitors click through that ad, MSN automatically puts the keywords there in the SID. Alternately, you can put your own code in there that corresponds to the ads you're running. When they arrive at the landing page, it sets the SID in a cookie.

    >>2. Does the "set cookie" code get placed on all entry pages?

    Right, or more conveniently, in your "global" or "header" file that is included on all pages so no matter where someone enters, if they have a SID in the URL, they will get a cookie for it.

    >>3. Is the "set cookie" code relevant as-is or do I have to modify it for my page?

    It will work on any site.
     
    TheHoff, Jun 8, 2006 IP
  15. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #15
    Thank you Hoff for your response.

    $link = "www.dpbolvw.net/mg101esagesa3fg2fesaefeqqw321335BC?sid=".$_COOKIE['sid'];
    Code (markup):
    How do I setup the code posted above on my page. I tried several ideas that I had but it didn't work. I'm not very adequate with php script yet. :( Just your occasional modifications here and there. Once I have some spare time though I intend to learn more.

    Here is my page in case your wondering: http://gamerentalguide.com/index.php. I will be putting this up for my GameFly link.

    Thank you,
    John
     
    grafx77, Jun 8, 2006 IP
  16. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Wherever you have a CJ link in your HTML like

    www.dpbolvw.net/mg101esagesa3fg2fesaefeqqw321335BC

    append it with this

    <? echo "?sid=".$_COOKIE['sid']; ?>

    If you use URL redirections like this

    dpbolvw.net/mg101esagesa3fg2fesaefeqqw321335BC?url=http://merchant.com

    append it with this

    <? echo "&sid=".$_COOKIE['sid']; ?>


    so your final link would like like

    dpbolvw.net/mg101esagesa3fg2fesaefeqqw321335BC?url=http://merchant.com<? echo "&sid=".$_COOKIE['sid']; ?>
     
    TheHoff, Jun 8, 2006 IP
  17. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #17
    Implemented both scripts and there seems to be two small problems.

    1. When I go to my index.php page, my page seems to load and act as normal, but when I use the sid= parameter within my tracking URL, I get a message like this at the top of the page- "Warning: Cannot modify header information - headers already sent by (output started at /home/giftgadg/public_html/gamerentalguide/index.php:6) in /home/giftgadg/public_html/gamerentalguide/index.php on line 13"

    Even though this "warning code" shows up at the top of the screen, the script works........until I browse other pages of my site. This is mentioned on #2.

    2. When I browse to other pages of my site, the cookie is not stored, so when I get back to my index.php page, the sid= parameter on my affiliate link is blank.

    Oh BTW.....on the index.php page the .php affiliate link is on the GameFly link underneath the heading "VIDEO GAME RENTAL CLUBS ARE GAINING ALOT OF POPULARITY"
     
    grafx77, Jun 8, 2006 IP
  18. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Anything that sets a cookie must be put before any other code is output to the browser. So before your index starts spitting out "<html><head>"...etc... you have to set the cookie before that.
     
    TheHoff, Jun 8, 2006 IP
  19. grafx77

    grafx77 Well-Known Member

    Messages:
    810
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    140
    #19
    Hoff, your da man!

    Everything works fine now, but there is one small problem yet again.

    All my tracking links look like this: http://gamerentalguide.com/adwatcher/tracker.php?t=23

    So when I append the &sid= to this link like this:
    http://gamerentalguide.com/adwatcher/tracker.php?t=23&sid=testing

    The cookie doesn't store the sid value and append it to the end of my affiliate link. Only when the link looks like this:
    http://gamerentalguide.com?sid=testing will the value be stored.

    Is there anyway around this?
     
    grafx77, Jun 8, 2006 IP
  20. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Is the code with setcookie at the top of tracker.php?
     
    TheHoff, Jun 8, 2006 IP