Problem/Motivation

Exception: API key is not set in the configuration. in Drupal\posthog\CookieReader->getCookieName() (line 60 of /var/www/drupal/web/modules/contrib/posthog/src/CookieReader.php).

on first login after module installation!

Problem 2:
In Cookie Reader we assume a certain name for the cookie we read.

The PH docs say:

By default, we store all this information in both a cookie and localStorage, which means PostHog can identify your users across subdomains. By default, the name of the cookie PostHog sets is ph_
_posthog and it expires after 365 days.

Mind ph_
_posthog
https://git.drupalcode.org/issue/posthog-3586186/-/blob/3586186-identify...

So this should be relatively reliable.

Still we should add a test which does something to create this cookie and then in PHP should check to read it for 3 reasons:
Ensure the functionality works as expected in general
The cookie name is not changed
The cookie value we read is not changed

Both last tests should contain a message that if this fails, probably PostHog changed the name and that should be checked first!

Please link the docs there: https://git.drupalcode.org/issue/posthog-3586186/-/blob/3586186-identify...

I also though if we should move the cookies prefix, suffix and value distinct_id into config variables, but I think that might be prone to errors. Please instead move them to constants in the cookie reader!

Steps to reproduce

Log in in a fresh installation

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork posthog-3586061

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anybody created an issue. See original summary.

anybody’s picture

Priority: Normal » Major
Issue summary: View changes

grevil made their first commit to this issue’s fork.

grevil’s picture

Title: Exception: API key is not set in the configuration. in Drupal\posthog\CookieReader->getCookieName() (line 60 of /var/www/drupal/web/modules/contrib/posthog/src/CookieReader.php). » Fix and add a test for the cookie reader, because the cookie name or value could change (externally)
Issue summary: View changes

anybody’s picture

@grevil nice catch, makes perfect sense this way!

grevil’s picture

Assigned: grevil » Unassigned

Alright, let's wait for the tests!

grevil’s picture

Assigned: Unassigned » anybody
Status: Active » Needs review

All green!! Ready to merge. Final review by @anybody.

anybody’s picture

Assigned: anybody » Unassigned
Status: Needs review » Reviewed & tested by the community

  • anybody committed 0f8bf00a on 2.x authored by grevil
    feat: #3586061 Fix and add a test for the cookie reader, because the...
anybody’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

grevil’s picture

Priority: Normal » Major

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.