• Hi does anyone know if its possible to make it so when someone accepts this plugin it will place cookies on a visitors machine but specific cookies/pixels on certain pages also. For example a facebook tracking pixel for a specific landing page?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ambyomoron

    (@josiah-s-carberry)

    This is precisely what the plugin does. However, you must provide the script that performs the desired action. The plugin only provides a place for you to record tha script, together with the logic that decides whether to execute the script or not, based on the visitor’s choice.

    Thread Starter slimmyweight

    (@slimmyweight)

    Hey Josiah thanks for the reply, I must not of explained my question very well.

    I understand how to make it so a cookie is only placed when they accept but I’m wanting to make it so different cookies are placed only on certain pages so for example a certain facebook tracking pixel when someone has visited a landing page. But that pixel is only placed on a certain page and only when they have accepted the cookie banner

    Ambyomoron

    (@josiah-s-carberry)

    So you need to put the script on the page itself, or you need to put it in functions.php, with a test for the page_id. The plugin provides a function to test whether the visitor has already accepted cookies, so you need to call that function within your script, in pseudo code:

    if user_has_accepted_cookies {
        if page_id = 'x' {
           write_some_cookie()
        }
        else if page_id = 'y' {
           write_a different_cookie()
        }
    }
    • This reply was modified 6 years, 7 months ago by Ambyomoron.
    Thread Starter slimmyweight

    (@slimmyweight)

    Thanks Josiah for the reply it is really helpful, I’m not a web developer but I know some c# so I understand the code you have written but in case I’ve miss understood anything.
    So if I place this code:

    
    if user_has_accepted_cookies {
        if page_id = 'x' {
           Write cookie/pixel code here
        }
    

    and place it in my functions.php it should work and make it that particular cookie will only be placed if they’ve accepted and when they are on that particular page depending on which page id I enter where x is?

    Thanks

    Ambyomoron

    (@josiah-s-carberry)

    Yes. You just have to find the function provided by the plugin that will tell you if the user has accepted cookies – I don’t know what it is off-hand, but it is hidden somewhere in the documentation. And, depending on the number of different pages, you might want to use use something other than if {}

    Also, you need to hook into something that wordpress knows about so that you code gets executed in the right place. Something like:

    add_action('wp_head', 'my_cookie_function', 1);
    function my_cookie_function() {
        if user_has_accepted_cookies {
            if page_id = 'x' {
                Write cookie/pixel code here
            }
        }
    }

    You will find the documentation for the actions into which you can hook here: https://codex.www.ads-software.com/Plugin_API/Action_Reference . That would be wp_head in the example above.

    To get the page id, I guess you would use something like get_the_id() (see https://developer.www.ads-software.com/reference/functions/get_the_id/ )

    You might also want to consider the action wp_enqueue_script(), which is used to queue up a javascript for execution.

    I’m not a web developer either, so I am a little out of my depths here. But as no one better qualified than I has stepped in, I have given what help I can.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘unique cookies for specific pages’ is closed to new replies.