Cookies only change value every two pages?

I am trying to implement some pixel tracking where I store certain values ​​in a cookie and then forward users to another page. If users buy a product after being submitted to an online store by us, the store adds an image tag to the page with our php script included. With the values ​​set in the cookie, we would like to track conversions.

I understand that this tracking technology has some limitations (for example, if the user turned off cookies or did not load images, but the direction my client wanted to go in).

The problem I am facing is that the cookie behavior is extremely ... random. I tried to track their values ​​(using var_dump so I don't have to wait for a page reload to see the cookie value), but it seems that the value for one field is only updated every two page reloads.

    setcookie("tracking[cn]", $cn, time()+3600*24*7,'/','mydomain.com');
    setcookie("tracking[t]", $t, time()+3600*24*7,'/','mydomain.com');
    setcookie("tracking[kid]", $kid, time()+3600*24*7,'/','mydomain.com');
    redirectTo($redirect_url);

      

the cn, t values ​​are exact, but for some reason the child is always wrong (taking the value of the previous child)

Any help would be hugely appreciated, I've been on this all evening! :)

+2


a source to share


2 answers


With cookies, you cannot display information before the cookie is created.



(I didn't realize I was doing this because I wasn't getting the error.)

+2


a source


I suspect the problem might be that some code sets $ cn, $ t and $ kid before these calls.



But I'm not sure.

0


a source







All Articles