How can I issue a cookie to my web visitors?

7 replies
I have PPC campaigns running and we'd like to do the following with one of the campaigns:

- Have the user enter our site through a PPC-specific landing page

- Issue a cookie to these users so that, if they click 'home' within the page menu or if they return to the site shortly thereafter, they see a different version of the homepage (don't get hung up on why - it's because this campaign is targeting a very specific market and we want to ensure they see a homepage that is specific to their industry).

Site is running on WP.

How would one accomplish this?
#cookie #issue #visitors #web
  • Profile picture of the author SandyUgale
    I guess its something like you like to have different versions of home page depends on criteria..this can be done with script probably PHP ..with coding we can call specific page ..but at this stage we are not very sure what exactly you like ..means requirement has very limited info to comment on final solution..also dont know where it would redirect..means several technical & non technical questions at this stage
    {{ DiscussionBoard.errors[6792259].message }}
  • Profile picture of the author wordpressmania
    If I write something while I am in dark with limited information I can not give you a accurate solution... PM me with more details... I will help you in my free time...
    {{ DiscussionBoard.errors[6795992].message }}
  • Profile picture of the author tweakr
    Do you have control over the link in the campaign? If so the easiest way would be to set a parameter on that url; something like
    Code:
    http://example.com/?ref=my-ppc
    than have some php code that checks for this parameter and sets a cookie if present.

    Here's some code that might help you out:

    I posted the code to pastebin
    {{ DiscussionBoard.errors[6799961].message }}
  • Profile picture of the author Tradeout
    This can be accomplished by setting the cookie on the specific page and then checking if the cookie exists on your home page to serve the content you require.
    {{ DiscussionBoard.errors[6812828].message }}
  • Profile picture of the author SteveJohnson
    Originally Posted by JimMichael View Post

    I have PPC campaigns running and we'd like to do the following with one of the campaigns:

    - Have the user enter our site through a PPC-specific landing page

    - Issue a cookie to these users so that, if they click 'home' within the page menu or if they return to the site shortly thereafter, they see a different version of the homepage (don't get hung up on why - it's because this campaign is targeting a very specific market and we want to ensure they see a homepage that is specific to their industry).

    Site is running on WP.

    How would one accomplish this?
    The easiest way to do it would be via a plugin that handles setting and reading the cookie, then loading the desired home page template using WP's template loading functions.

    It wouldn't be enormously complicated, but you'll need to find someone who understands the WP templating system and can write a decent plugin.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[6814150].message }}
  • Profile picture of the author Big Squid
    Here's what you need to do:

    As soon as they land on your page, you start a $_SESSION & set a $_COOKIE. When they come back you start another $_SESSION from the $_COOKIE. If there is no cookie set, then the cookie has expired, the user deleted it, or it was never set (ie. new visitor).

    Then, based off that you display the appropriate home page. For instance,
    if ( $_SESSION is set ) then ( display HomePage#1)
    else ( display HomePage#2)

    The code shouldn't take more than 10 minutes to write. Shouldn't cost you more than $50.
    {{ DiscussionBoard.errors[6841148].message }}
  • Profile picture of the author Big Squid
    it was less than 10...

    Here's the code you'll need..:

    This code should be put on your CPC Landing page. It will set a random cookie using uniqid(). That cookie will last for 30 days, which you can change if you want by changing the "30" to however many days you desire.
    PHP Code:
    <?php
        session_start
    ();
        
    $_SESSION['trigger'] = uniqid();
         
    setcookie('trigger'$_SESSION['trigger'], time() + (60 60 24 *  30)); //cookie is set to expire in 30 days.
    ?>
    This is the code (BELOW) that should be place first, ahead of all other codes on your home page. You will need to add this to the top of the header.php file located in your active wordpress theme.

    This checks to see if the cookie is set. If it is, it will redirect them to a new page, currently set at google.com - so you'll have to replace that url otherwise you'll be sending all your traffic away.

    Also, I set a session just in case the user denies all cookies. If they do, then this code can at least catch them through the session.
    PHP Code:
    <?php
        session_start
    ();
        if(isset(
    $_SESSION['trigger']) || isset($_COOKIE['trigger'])) {
            
    $url 'http://www.google.com'// change this to go where you want it to
            
    header('Location: '.$url);
        }
    ?>
    Hope that helps...
    {{ DiscussionBoard.errors[6841233].message }}

Trending Topics