• Resolved eugeneormktg

    (@eugeneormktg)


    My client requested that I add cookies to their website so they can track first time users, returning users, and subscribers. It is my understanding that the cookies script can be inserted in the functions file, or by using a plug-in like Cookiebot. What I am unclear about is where do I find the required information to create the cookie, such as name, type etc? I understand the tutorials but most of them assume that I know the name etc. Apologies in advance if this is not worded properly – this is my first time adding cookies.

    • This topic was modified 5 years, 2 months ago by eugeneormktg. Reason: added plugin name

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • What is the use case here? Suppose, once you create the cookie, how do you plan on using that to distinguish first time users, returning users, and subscribers?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You could add something like this in the a plugin or your functions.php

    add_action( 'wp_head', 'resource_registered', 30, 2 );
    function resource_registered( $entry_id, $form_id ) {
            $cookie_value = 'abc' // some logic here to set the value of the cookie
            setcookie( 'user_status', $cookie_value, time() + 31556926, '/' );
            }
    }
    
    Thread Starter eugeneormktg

    (@eugeneormktg)

    I don’t know how to distinguish first time users, returning users, and subscribers – is that something that gets set up in Google Analytics? This is the part that I can’t find information on, I understand where to put the code, but the tutorials I’m finding assume I know “$cookie_value = ‘abc’ // some logic here to set the value of the cookie” – and I am missing this key element of the process. CAn either of you please elaborate on that detail?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    If there’s no cookie, they’re a first time user. If they’r e logged in when you set the cookie, they’re a subscriber. If the cookie exists, they’re a returning user.

    https://www.wpbeginner.com/wp-tutorials/how-to-set-get-and-delete-wordpress-cookies-like-a-pro/

    Thread Starter eugeneormktg

    (@eugeneormktg)

    Thank you Steve – does that mean I can paste the snippet you sent verbatim? or do I need to change “$cookie_value = ‘abc’ // some logic here to set the value of the cookie” to something else to work correctly?

    Thread Starter eugeneormktg

    (@eugeneormktg)

    Thanks everyone – a friend sent me the following script and it worked.

    function resource_registered($entry_id, $form_id) {
        $value = true;
        setcookie('returning_user', $value, time() + 31556926, '/');
    }
    
    if (isset($_COOKIE['returning_user']) && $_COOKIE['returning_user'] == true) {
        // do stuff if cookie is set
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need Help Adding Cookies’ is closed to new replies.