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

Target by specific countries and/or country group #1271

Merged
merged 27 commits into from
Feb 7, 2025

Conversation

charleycampbell
Copy link
Contributor

@charleycampbell charleycampbell commented Jan 22, 2025

Co-authored with @LAKSHMIRPILLAI

What does this change?

TL;DR Adds in new logic to enable targeting by individual countries

Previously when we set up tests in the RRCP for epics or banners we can target audiences by region, but we have a new requirement to enable us to target by individual countries, like just Germany.

We have added in a new dropdown in the RRCP [SAC PR link] meaning that users can target by region, individual country or both! This is passed through to the SDC model via the targeted countries field. From here, we then check wether or not to display that epic. The targeted country comes through as country name (like Germany) but in our logic we convert that to the country code (DE) which then, depending on the users location will determine whether or not to show the epic.

We have test cases in geolocations which might help in understanding the newer logic.

For more information, as well as the testing see here

How to test

  1. Create a banner or epic or header test in the RRCP
  2. Set region targeting using a new country dropdown menu
  3. Save the test (you may need to reorder the tests)
  4. On DCR, head to an article and using the bookmarklet change the geolocation to the country you set
  5. You should see the epic/banner/header relevant to your country selection
  6. Change the geolocation again to a different country should not show the same epic/banner/header

How can we measure success?

Have we considered potential risks?

Images

Accessibility

…eaning we can specifically target countries

added in logic which will check for the country name and convert it into the country code as well as checking for a country group. hopefully they are an OR statement!
… DB. we convert it to a country code so it can check against the user payload which has the country code

Added in a number of unit tests to cover the new logic including the country code converter
… DB. we convert it to a country code so it can check against the user payload which has the country code

Added in a number of unit tests to cover the new logic including the country code converter
@charleycampbell charleycampbell marked this pull request as ready for review January 27, 2025 10:10
@charleycampbell charleycampbell requested a review from a team as a code owner January 27, 2025 10:10
…cated) locations field as well as the string of arrays for countries
…nge refelct that including removing of mapping from country code to country name

Updated unit tests
minor renaming so it is clearer
return foundCountryGroupId || 'International';
};

//inCountryGroups is a bad name now that it accepts country names separately from country groups
Copy link
Member

Choose a reason for hiding this comment

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

Shall we rename it then?
Something like inTargetedCountry(...) perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion

@@ -623,3 +636,8 @@ export const addRegionIdToSupportUrl = (originalUrl: string, countryCode?: strin

return originalUrl;
};

const countryNameToCodeMap: Record<string, string> = {};
Copy link
Member

Choose a reason for hiding this comment

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

can this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it can!

@@ -58,6 +58,23 @@ function canShowAbandonedBasketBanner(
return daysSince(new Date(abandonedBasketBannerLastClosedAt), now) > 0;
}

export const isCountryTargetedForBanner = (
Copy link
Member

Choose a reason for hiding this comment

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

These functions can be deleted once the migration is complete and locations is gone, right?
We could avoid all the duplication if this logic happened inside inCountryGroups, but if it's all going away soon then it's not really an issue!

Copy link
Contributor Author

@charleycampbell charleycampbell Feb 6, 2025

Choose a reason for hiding this comment

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

Yeah exactly. It's really not a very elegant solution throughout but once the locations field is removed we can remove this function and be able to pass inTargetedCountry straight into the selection.

inTargetedCountry(
    targeting.countryCode,
    test.regionTargeting?.targetedCountryGroups || [],
    test.regionTargeting?.targetedCountryCodes || [],
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although I think the Epic is slightly different because it's using Filter and is expecting a boolean and not a function so we may have to treat that different but for the other components the above should suffice!

Copy link
Member

Choose a reason for hiding this comment

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

👍 we can do a little refactor later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a plan!

Copy link
Member

@tomrf1 tomrf1 left a comment

Choose a reason for hiding this comment

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

great!

@charleycampbell charleycampbell merged commit 8a2b0de into main Feb 7, 2025
4 checks passed
@charleycampbell charleycampbell deleted the cc/targeting-by-country branch February 7, 2025 10:57
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.

3 participants