Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_pk_testcookies set while using "disableCookies" #15000

Closed
davbecker opened this issue Oct 13, 2019 · 10 comments · Fixed by #15107
Closed

_pk_testcookies set while using "disableCookies" #15000

davbecker opened this issue Oct 13, 2019 · 10 comments · Fixed by #15107
Assignees
Labels
Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Milestone

Comments

@davbecker
Copy link

I'm usign Matomo 3.12.0-b5 and several "_pk_testcookie" set by the hasCookie() function despite I am using "_paq.push(['disableCookies']);".

Now I'm wondern if it is a bug? Feature? Or am I missing something? Because setting cookies without the users consent could be a potential GDPR issue.

Tracking code example:

<script type="text/javascript">
        var _paq = window._paq || [];
        _paq.push(['disableCookies']);
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function() {
            var u="URL";
            _paq.push(['setTrackerUrl', u+'matomo.php']);
            _paq.push(['setSiteId', '1']);
            var websiteIdDuplicate = 2;
            _paq.push(['addTracker', piwikUrl = u+'matomo.php', websiteIdDuplicate]);
            var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
            g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js';
            s.parentNode.insertBefore(g,s);
        })();
</script>

Cookies:
matomo cookies

@Findus23
Copy link
Member

In theory Matomo only creates testcookies when you don't have set disableCookies.

matomo/js/piwik.js

Lines 3878 to 3887 in 1091c61

function hasCookies() {
if (configCookiesDisabled) {
return '0';
}
var testCookieName = getCookieName('testcookie');
setCookie(testCookieName, '1');
return getCookie(testCookieName) === '1' ? '1' : '0';
}

Is it possible that the cookies were created before you changed the Tracking code and are just left on your browser?

@tsteur
Copy link
Member

tsteur commented Oct 13, 2019

Looking at the code this seems indeed the case that they are likely from some previous test cause disableCookies is right the second method that is being executed.

I'll close this issue for now as it seems like a user issue but please comment if that's not the case. If you can reproduce an issue there after clearing please comment and we reopen. Be great to have your exact tracking code to reproduce this issue then (without your idsite and matomo URL.)

@tsteur tsteur closed this as completed Oct 13, 2019
@tsteur tsteur added the worksforme The issue cannot be reproduced and things work as intended. label Oct 13, 2019
@davbecker
Copy link
Author

Seems right! I've tested it today with two other computers, no cookies were set. On my local machine it might be just a local config issue. Because if im deleting all cookies and the whole website data in my browser cookies are still set. Thats why I was wondering.

tl;dr:
You guys are right, in live environment everything works as expected. Thanks for the hint! :)

@mattab mattab added this to the 3.12.0 milestone Oct 27, 2019
@falk1020
Copy link

I could not solve the testcookie problem...
It is set in all browsers / all machines.
Matomo 3.12.0, just updated to this version.

Can someone help me please?

Frontend JS Code (Loading Matomo after the page is loaded)

`<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['disableCookies']); /* important for users who don't accept cookies */
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);

function embedTrackingCode() {
var u="//matomo.mysecretdomain.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);

var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
}

if (window.addEventListener) {
window.addEventListener("load", embedTrackingCode, false);
} else if (window.attachEvent) {
window.attachEvent("onload",embedTrackingCode);
} else {
embedTrackingCode();
}
</script>`

@Gregor-Agnes
Copy link

Gregor-Agnes commented Oct 30, 2019

We can confirm: Since update to 3.12.0 we get the _pk_testcookie..undefined on all installations when setting "disableCookies". Can this be confirmed and fixed? :)

<!-- Matomo -->
<script type="text/javascript">
  var _paq = _paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['disableCookies']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//matomo.mydomain.org/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

<noscript>
	<!-- Matomo Image Tracker-->
	<img src="https://matomo.mydomain.org/piwik.php?idsite=1&rec=1" style="border:0" alt="" />
	<!-- End Matomo -->
</noscript>

@C-y-b-o-t
Copy link

I also can confirm this. "disableCookies" is enabled but "_pk_testcookie..undefined" gets set.
Matomo 3.12.0.

@stadtmensch
Copy link

Same here. _pk_testcookie..undefined is set and I also have _paq.push(["disableCookies"]);
Matomo 3.12.0

@tsteur
Copy link
Member

tsteur commented Oct 30, 2019

It seems detectBrowserFeatures() is executed while creating the tracking instance before the cookies are being disabled... Note: This test cookie will be deleted again right away but I understand it's still an issue.

The only thing I can image is to revert https://github.com/matomo-org/matomo/pull/14495/files

@mattab @Findus23 any thoughts?

I looked into calling detectBrowserFeatures at a later point but it seems to be used by various methods. It might still possible though with a small refactor to make it maybe work for both. Eg https://github.com/matomo-org/matomo/blob/3.12.0/js/piwik.js#L6671 would need to be removed etc.

@tsteur tsteur reopened this Oct 30, 2019
@tsteur tsteur added Regression Indicates a feature used to work in a certain way but it no longer does even though it should. and removed worksforme The issue cannot be reproduced and things work as intended. labels Oct 30, 2019
@sgiehl sgiehl modified the milestones: 3.12.0, 3.13.0 Nov 2, 2019
@tsteur tsteur self-assigned this Nov 4, 2019
@jfqd
Copy link

jfqd commented Dec 4, 2019

This issue still exists in 3.13.0. We use disableCookies and the test-cookie is always set. Our tracking code looks like:

<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['disableCookies']);
  _paq.push(['addDownloadExtensions', "webm"]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  _paq.push(['trackVisibleContentImpressions']);
  (function(){
  var u="https://matomo.example.com";
  _paq.push(['setTrackerUrl', u+'/matomo.php']);
  _paq.push(['setSiteId', '1']);
  var d=document,
  g=d.createElement('script'),
  s=d.getElementsByTagName('script')[0];
  g.type='text/javascript';
  g.defer=true;
  g.async=true;
  g.src=u+'/matomo.js';
  s.parentNode.insertBefore(g,s);
  })();
</script>

So #15107 does not fix it for us.

@tsteur
Copy link
Member

tsteur commented Dec 4, 2019

This will be fixed in #15225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants