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

Persona research screener banner #8192

Merged

Conversation

jimchamp
Copy link
Collaborator

@jimchamp jimchamp commented Aug 15, 2023

Closes #8180

On login, checks a patron's eligibility to be shown a CTA to respond to a persona research survey. If eligible, a new cookie will be set. If the cookie is set, a dismissible banner will be shown on the patron's "My Books" page.

To be eligible, each of the following must be true:

  • The current month is August
  • The patron's account must be at least 90 days old
  • The domain of the email address that is linked to the patron's account is from an educational organization
  • The patron has borrowed at least three books in the past

Notes about the data set:
Date accessed: 10 August 2023
Data set size: ~2.7 MB
Flattened data set size: ~125.9 kB
Number of institutions: 9936
Number of domains: 10180

Remaining tasks

  • Set href of banner link

Technical

Script used to flatted the edu domains: https://gist.github.com/jimchamp/f67ef14c3bcf11593f393ee5288f6476

Testing

Screenshot

image

Stakeholders

@jimchamp jimchamp force-pushed the 8180/feature/screener-banner branch 3 times, most recently from f650219 to 8076cc9 Compare August 15, 2023 22:54
@mekarpeles
Copy link
Member

{'history': {'limit': '1', 'offset': '0', 'items': [{'userid': '@mekarpeles', 'listname': 'loan_history', 'identifier': '100mostinfluenti00seym', 'updatedate': '2017-10-21 09:16:55', 'title': 'The 100 most influential books ever written : the history of thought from ancient times to today', 'mediatype': 'texts'}]}}

@mekarpeles
Copy link
Member

Possibly copy change?

Are you a K-12 or University educator or student? Please [ help us improve ].

Comment on lines 471 to 475
sorted_edu_domains = utils.get_edu_domains()

i = bisect_left(sorted_edu_domains, domain)
if i != len(sorted_edu_domains) and sorted_edu_domains[i] == domain:
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to use a set instead of a list and get constant time lookup

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not able to cache sets currently, so have used a dict instead of a set.

@@ -1314,6 +1314,16 @@ def get_location_and_publisher(loc_pub: str) -> tuple[list[str], list[str]]:
return ([], [loc_pub.strip(STRIP_CHARS)])


@functools.cache
def get_edu_domains():
f = open('static/edu-domains.txt')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think somewhere in scripts we may have an e.g. of abspath being used (re: whether this relpath references the file as we want)

Copy link
Member

@mekarpeles mekarpeles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to...

  • 1. check the relative edu file path (to see if it's working)
  • 2. use a set instead of list for edu domain lookup (is email.split('@')[-1] in edu set?) -- add archive.org as domain (for testing)
    • Can we link to a gist that can be used to e.g. update this list of domains in the future if the corresponding 3rd party github repo changes?
  • 3. (optional) move functools.cache to memcache w/ 1 mo (since webheads have limited RAM)
  • 4. only set cookie if admin (for now)
  • 5. add year=2023 to month=8 check (so we don't show banner in 2024)
  • 6. (optional) move banner dismiss check to cookies rather than account prefs?

@@ -1314,6 +1314,16 @@ def get_location_and_publisher(loc_pub: str) -> tuple[list[str], list[str]]:
return ([], [loc_pub.strip(STRIP_CHARS)])


@functools.cache
def get_edu_domains():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_edu_domains():
def get_edu_domains():
"""
This list created using this gist: https://gist.github.com/jimchamp/f67ef14c3bcf11593f393ee5288f6476 on https://raw.githubusercontent.com/Hipo/university-domains-list/master/world_universities_and_domains.json.
See: https://github.com/internetarchive/openlibrary/issues/8180
"""

@mekarpeles mekarpeles added the Priority: 1 Do this week, receiving emails, time sensitive, . [managed] label Aug 16, 2023
@mekarpeles mekarpeles self-assigned this Aug 19, 2023
Copy link
Member

@mekarpeles mekarpeles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provisional lgtm

Comment on lines +408 to +412

# Don't overwrite the cookie, which will contain banner display preferences
if not web.cookies().get('se', False):
self.set_screener_cookie(ol_account)

Copy link
Collaborator Author

@jimchamp jimchamp Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important Note
We are determining if a patron is eligible for the survey whenever they log in. The problem with this approach is that people who chose the "Remember me" option while logging in will likely not see the banner.
Not sure how to address this issue. Do we have a means of logging everybody out at once? Doing so before the campaign would ensure that everybody who is eligible and visits will see the banner, but would also be an annoyance for our patrons.
Maybe we set the screener cookie on the My Books page instead of at login? This would avoid logging everybody out, but we may still miss eligible folks who seldomly visit their My Books page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. If we do a deploy that might log people out? For now, maybe it's okay if we ignore this case (let's see how many patrons reply). It's a really good point and there are ways to log everyone out.

- Add `archive.org` to educational domains (for testing purposes)
- Store edu domains in a `dict` for constant-time look up
- Cache edu domains using memcached
- Only display banners during August 2023
- Only display banners for `admin`s (for testing purposes)
- Update banner copy
@jimchamp jimchamp force-pushed the 8180/feature/screener-banner branch from 8aa7a4c to ffcaf39 Compare August 23, 2023 15:52
@jimchamp jimchamp marked this pull request as ready for review August 23, 2023 15:58
$# Start : Persona research banner
$if user:
$if user.is_screener_eligible():
$ banner_key = 'pr2308'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read as: Persona Research 2023-08

@jimchamp jimchamp changed the title [WIP] Persona research screener banner Persona research screener banner Aug 23, 2023

See: https://github.com/internetarchive/openlibrary/issues/8180
"""
p = Path(Path.cwd(), 'static', 'edu-domains.txt')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're unsure about setting the path this way, we could do something like this:

with Path('/openlibrary/openlibrary/templates/about/team.json').open(
mode='r'
) as f:

Comment on lines 447 to 449
# It is August 2023:
if (now := datetime.now()) and now.month != 8 and now.year != 2023:
return False
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to update these dates, as time is running short.


See: https://github.com/internetarchive/openlibrary/issues/8180
"""
p = Path(Path.cwd(), 'static', 'edu-domains.txt')
Copy link
Collaborator

@cdrini cdrini Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Side note; the / operator can be used here!)

Suggested change
p = Path(Path.cwd(), 'static', 'edu-domains.txt')
p = Path.cwd() / 'static' / 'edu-domains.txt'

@jimchamp jimchamp added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Sep 8, 2023
@jimchamp
Copy link
Collaborator Author

jimchamp commented Sep 8, 2023

Noting that the edu domain textfile is not being added when the PR deployment script is used.

@jimchamp jimchamp removed the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Sep 8, 2023
@mekarpeles mekarpeles added this to the Sprint 2023-09 milestone Sep 9, 2023
@mekarpeles mekarpeles merged commit 8f0b4b4 into internetarchive:master Sep 11, 2023
@jimchamp jimchamp deleted the 8180/feature/screener-banner branch September 25, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: 1 Do this week, receiving emails, time sensitive, . [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create banner for Persona Research screener survey
3 participants