Skip to content

PL Launch 2023 - Show default homepage hero banner to int'l audiences - #51356

Merged
megcrenshaw merged 11 commits into
stagingfrom
pl-homepage-banner-intl
Apr 20, 2023
Merged

PL Launch 2023 - Show default homepage hero banner to int'l audiences#51356
megcrenshaw merged 11 commits into
stagingfrom
pl-homepage-banner-intl

Conversation

@kelbyhawn

@kelbyhawn kelbyhawn commented Apr 14, 2023

Copy link
Copy Markdown
Contributor

Show the default homepage hero banner to international audiences and the PL superhero banner to US only.

Asana task: https://app.asana.com/0/0/1204402039772899

Related PR:

Testing story

[from Meg] The homepage.rb file currently has no tests. To convince myself that the showInternationally flag was working as expected, I used the announcements test file for inspiration.

I had three attempted testing strategies and landed on the last one:

  1. I was originally going to stub out the @@announcements_data variable using Homepage.class_variable_set(:@@announcements_data, {...}). But that approach meant that the vast majority of the test file was hard-to-parse JSONs, or hard-to-read updates to a single JSON.
  2. Then, I was going to use a separate file as the announcements test file does. But we're needing to test banners with different showInternationally flags, and our current banner configuration returns the very first banner it finds:
    # We have a banner. Add the ID to the hash that we return.
    return banner.merge({id: banner_id_for_page})
  3. I ended up creating a separate file for each of the showInternationally flag configurations –– true, false, and no flag. I don't love that there is quite a bit of repeated code for each JSON, but I do think it is more readable than the approach in (1).

Links

[from Meg] Asked Platform about best practices for querying location here https://codedotorg.slack.com/archives/CFTFD6BPV/p1681909723548929?thread_ts=1680634885.139079&cid=CFTFD6BPV

@kelbyhawn
kelbyhawn requested review from a team and dmcavoy April 14, 2023 19:44

@megcrenshaw megcrenshaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm confused about the product requirement –– do we want to show the page for English users or for users inside the US? It looks like this PR will show the banner for any English user, including English users in, say, India or Australia.

@dmcavoy

dmcavoy commented Apr 17, 2023

Copy link
Copy Markdown
Contributor

Good question Meg. The goal is to show the PL banner just to United States users. Is it possible to do that instead of relying on language to try to capture that?

@kelbyhawn

Copy link
Copy Markdown
Contributor Author

Good question Meg. The goal is to show the PL banner just to United States users. Is it possible to do that instead of relying on language to try to capture that?

I don't think we have the functionality for the homepage.json banners to show based off of geolocation (yet?) — I'll look into it.

@kelbyhawn

Copy link
Copy Markdown
Contributor Author

For more context — this is what we did last year for the CSA launch hero banner that had similar audience requirements (Brendan helped me pair on this):

@megcrenshaw

Copy link
Copy Markdown

Looks like this is where we set the language config:

# If the banner has an array of languages, then the current language must be one of them.
next if banner["languages"] && !banner["languages"].include?(request.language)

I believe we could use a similar pattern for country, but it's not currently configured. Depending on how high priority this is, one of us could implement this functionality for, Kelby, you to use. (Kelby, I'm sure you could get this working too, but I'm guessing learning Ruby wasn't part of the job description 😅 .)

@dmcavoy

dmcavoy commented Apr 17, 2023

Copy link
Copy Markdown
Contributor

@megcrenshaw thank you for looking into this. This is high priority as we are sending lots of traffic to pages that don't make any sense for them. Could you send some time today or tomorrow helping Kelby to get this working?

@kelbyhawn

Copy link
Copy Markdown
Contributor Author

Looks like this is where we set the language config:

# If the banner has an array of languages, then the current language must be one of them.
next if banner["languages"] && !banner["languages"].include?(request.language)

I believe we could use a similar pattern for country, but it's not currently configured. Depending on how high priority this is, one of us could implement this functionality for, Kelby, you to use. (Kelby, I'm sure you could get this working too, but I'm guessing learning Ruby wasn't part of the job description 😅 .)

I just tried that in this commit but it wasn't working 😅 maybe I missed something though?

@megcrenshaw

megcrenshaw commented Apr 17, 2023

Copy link
Copy Markdown

@dmcavoy Yep, on it!
@kelbyhawn Ah, brilliant! I missed that. You're way ahead of me. The request object doesn't include the country, but we can use this pattern:

location = Geocoder.search(user.current_sign_in_ip).first
country = location&.country_code&.to_s&.downcase

Want to try the following?

# If the banner has an array of countries, then the current country must be one of them.
location = Geocoder.search(user.current_sign_in_ip).first
country = location&.country_code&.to_s&.downcase
next if banner["countries"] && !banner["countries"].include?(country)

Then try us (lowercase) in the JSON. Or you can do &.upcase in the ruby file (instead of &.downcase) with capitalized US in the JSON –– whatever feels more intuitive to you.

If that doesn't work, let me know and we can either pair on it or I can take a deeper look solo. Thanks, Kelby, for starting on this!

Comment thread pegasus/src/homepage.rb Outdated
Comment on lines +34 to +38
# If the banner is shown internationally don't show in the US.
# If the banner is not shown internationally, show in the US.
location = Geocoder.search(request.ip)&.first
in_us = location&.country_code.to_s.casecmp?('us')
next unless banner["showInternationally"] ^ in_us

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

questions:

  1. how often is request.ip set? is it as reliable as user.current_sign_in_ip?
  2. does this codepath work (no errors) when request.ip is nil?
  3. in the case where request.ip is nil, are we ok with showing only outside us?
  4. I'm not sure about taking away the option to display banners globally. isn't this something we'll want to do for HOC?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good questions.
1-2) We can't use current_sign_in_ip because the user may not be signed in and we're on pegasus. But I don't know how often request.ip is set.
I went to this thread https://codedotorg.slack.com/archives/C0T0PNTM3/p1600671794018400 and it looks like the most established pattern is to be using request.country instead of request.location.country_code. @kelbyhawn thoughts about trying the following instead?

# remove location line
in_us = request.country.to_s.casecmp?('us')
next unless banner["showInternationally"] ^ in_us
  1. @dmcavoy do you know preferred behavior when we don't know the user's country?
  2. There are three options with the showInternationally flag:
  • false –– only show in the US
  • true –– only show outside of the US
  • no flag –– show everywhere

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. There are three options with the showInternationally flag:
  • false –– only show in the US
  • true –– only show outside of the US
  • no flag –– show everywhere

oh interesting! how is "show everywhere" implemented? the behavior I'm seeing makes me think that "no flag" will behave like false:

irb(main):001:0> nil ^ false
=> false
irb(main):002:0> nil ^ true
=> true

@dmcavoy dmcavoy Apr 18, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we don't know a users country I think it would be good to default to the US banner for now as thats our primary audience

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh yikes, Dave! Good call –– we tested this manually, but I think didn't cover all the cases.

@kelbyhawn I think either (a) we pair again to get this working, or (b) I pull down the branch and make the commit myself. Do you have a preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@megcrenshaw , given the need for thorough validation on our side, I'd encourage you to pull down the branch and make any changes needed, rather than going through Kelby for each update.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I might go ahead and add unit tests for this part too –– it will help me believe it's working

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That works for me @megcrenshaw, and thanks @davidsbailey for reviewing this!

@megcrenshaw
megcrenshaw force-pushed the pl-homepage-banner-intl branch from 156556d to e4a522f Compare April 19, 2023 14:14
@megcrenshaw

Copy link
Copy Markdown

Just updated this file with refactored logic and some tests –– @breville and @davidsbailey would love for y'all to take a look when you're able! @kelbyhawn tagging you just to give you an update on progress.

Comment thread pegasus/src/homepage.rb Outdated
# If the banner has an array of languages, then the current language must be one of them.
next if banner["languages"] && !banner["languages"].include?(request.language)

# If the banner has an showInternationally flag,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not blocking, very minor typo: an should be a.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks!

@davidsbailey davidsbailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Super glad to see this go out with test coverage. ⚓ ship it!

banner = Homepage.get_announcement_for_page("homepage", @request)
assert_equal("show-everywhere", banner[:id])
end
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these tests are awesome, thanks for adding these!

I feel bad even mentioning this, but as part of the effort to separate dashboard from pegasus, we are trying to avoid cross-project dependencies like this, and so in the future any tests on pegasus pages should go in pegasus/test. this is the ideal dependency graph:

Screenshot 2023-04-19 at 9 29 26 AM

this is my bad for not setting up linting rules preventing this kind of cross-project dependency, which I have been meaning to do for some time now. so for now I'm just going to ask that any additional tests for pegasus code be located in pegasus/test. 🙏

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh good call –– @kelbyhawn can I go ahead and update this? I hate shipping code that needs a refactor 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@megcrenshaw yes, absolutely! How much time do you think this'll add before it can be merged? (Only asking due to the AI banner dependency 🙃)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Give me like 15 minutes –– I have it moved with tests passing, but cleaning up a few things. Then it needs to go through drone ... so end of day your time

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just pushed new stuff. @davidsbailey do you want to take another look? It's my first rodeo writing a pegasus unit test, but the test structure didn't change. Perhaps if there are requested refactors, I can tackle them in a separate PR

Comment thread pegasus/src/homepage.rb
Comment on lines +34 to +37
# If the banner has a showInternationally flag,
# only show if exactly one of showInternationally or location_unknown_or_usa are true
location_unknown_or_usa = request.country.nil? || request.country.to_s.casecmp?('us')
next if banner.key?("showInternationally") && !(banner["showInternationally"] ^ location_unknown_or_usa)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💯

@davidsbailey davidsbailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for moving these tests Meg! LGTM once drone passes.

I do have one question: which bucket do we fall into when viewing these pages in local development? I don't think the answer should block this PR, but worth considering what we want the local experience to be.

@kelbyhawn

Copy link
Copy Markdown
Contributor Author

@megcrenshaw feel free to merge this w/o me when it's ready (unless it's better practice that I do it?)

@megcrenshaw

Copy link
Copy Markdown

@megcrenshaw feel free to merge this w/o me when it's ready (unless it's better practice that I do it?)

Ah, good call! It's ready. I'll merge 🥳

@megcrenshaw
megcrenshaw merged commit 03ded22 into staging Apr 20, 2023
@megcrenshaw
megcrenshaw deleted the pl-homepage-banner-intl branch April 20, 2023 19:38
@megcrenshaw

Copy link
Copy Markdown

thanks for moving these tests Meg! LGTM once drone passes.

I do have one question: which bucket do we fall into when viewing these pages in local development? I don't think the answer should block this PR, but worth considering what we want the local experience to be.

@davidsbailey great question. When Kelby and I tested this locally, the country comes back as RD (reserved). What do you see are potential options here? Elijah had some ideas here https://codedotorg.slack.com/archives/CFTFD6BPV/p1681839473513649?thread_ts=1681767673.939399&cid=CFTFD6BPV

@davidsbailey

Copy link
Copy Markdown
Member

thanks for moving these tests Meg! LGTM once drone passes.
I do have one question: which bucket do we fall into when viewing these pages in local development? I don't think the answer should block this PR, but worth considering what we want the local experience to be.

davidsbailey great question. When Kelby and I tested this locally, the country comes back as RD (reserved). What do you see are potential options here? Elijah had some ideas here https://codedotorg.slack.com/archives/CFTFD6BPV/p1681839473513649?thread_ts=1681767673.939399&cid=CFTFD6BPV

my input would just be to pick what you want the behavior to be, and have your code provide that behavior when the country code is RD. so, if you want it to give the US behavior, then location_unknown_or_usa = request.country.nil? || request.country.to_s.casecmp?('us') || .... ('RD')

@davidsbailey

Copy link
Copy Markdown
Member

it sounds like this is time-sensitive, so feel free to do in a follow-up PR.

@megcrenshaw

Copy link
Copy Markdown

@kelbyhawn do you want the local setup to behave like the US? If so, I'll create a followup PR to address that.

@kelbyhawn

Copy link
Copy Markdown
Contributor Author

@kelbyhawn do you want the local setup to behave like the US? If so, I'll create a followup PR to address that.

@megcrenshaw yes, that would be great thanks!

@kelbyhawn kelbyhawn changed the title Pl Launch 2023 - Show default homepage hero banner to int'l audiences PL Launch 2023 - Show default homepage hero banner to int'l audiences May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants