Skip to content

Send today's article count and contentType in banner requests - #3954

Merged
tomrf1 merged 12 commits into
mainfrom
tf-daily-ac
Mar 3, 2022
Merged

tomrf1 merged 12 commits into
mainfrom
tf-daily-ac

Conversation

@tomrf1

@tomrf1 tomrf1 commented Feb 10, 2022 •

Copy link
Copy Markdown
Member

SDC PR: guardian/support-dotcom-components#624

This PR makes the client send 2 new fields in the targeting payload to SDC for banners:

  • contentType
  • articleCountToday (if available)

Screen Shot 2022-02-10 at 12 03 09

alreadyVisitedCount: number;
engagementBannerLastClosedAt?: string;
subscriptionBannerLastClosedAt?: string;
weeklyArticleHistory?: WeeklyArticleHistory;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this field isn't used


export const getDailyArticleCount = (): DailyArticleCount => {
// Returns undefined if no daily article count in local storage
export const getDailyArticleCount = (): DailyArticleCount | undefined => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the return type here because undefined is a more deliberate signal that there is no article count. This is consistent with the weekly article count.

@oliverlloyd

Copy link
Copy Markdown
Contributor

Could we move this code out of App.tsx and down into the respective components? We're about to delete App.tsx and so we don't want to add any more logic to this file.

Wait, what? Deleting App, what?!

There are documents here and here explaining the reasoning and here is a PR introducing Islands, the replacement for App.

So what do I do with my React state?

We moving global state down into local components. This means where you had shared global App state it should be duplicated and moved into the specific components. There are examples of this in other PRs

I'm still confused

It's just confusing. Please do reach out to the team; we're extremely happy to pair on this!

@github-actions

github-actions Bot commented Feb 23, 2022 •

Copy link
Copy Markdown

Size Change: -69.7 kB (-5%) ✅

Total Size: 1.36 MB

Filename Size Change
dotcom-rendering/dist/1924.js 5.05 kB +12 B (0%)
dotcom-rendering/dist/1924.legacy.js 5.12 kB +10 B (0%)
dotcom-rendering/dist/2058.js 5.79 kB +11 B (0%)
dotcom-rendering/dist/2058.legacy.js 5.96 kB +13 B (0%)
dotcom-rendering/dist/226.js 0 B -7.43 kB (removed) 🏆
dotcom-rendering/dist/23.js 5.86 kB +188 B (+3%)
dotcom-rendering/dist/23.legacy.js 6.17 kB +209 B (+4%)
dotcom-rendering/dist/2879.js 7.02 kB +180 B (+3%)
dotcom-rendering/dist/2879.legacy.js 7.29 kB +203 B (+3%)
dotcom-rendering/dist/2949.js 5.16 kB +187 B (+4%)
dotcom-rendering/dist/2949.legacy.js 5.37 kB +206 B (+4%)
dotcom-rendering/dist/3213.js 13.9 kB +502 B (+4%)
dotcom-rendering/dist/3213.legacy.js 14.3 kB +529 B (+4%)
dotcom-rendering/dist/3215.js 5.62 kB +176 B (+3%)
dotcom-rendering/dist/3215.legacy.js 5.78 kB +202 B (+4%)
dotcom-rendering/dist/3270.js 4.91 kB +113 B (+2%)
dotcom-rendering/dist/3270.legacy.js 5.06 kB +112 B (+2%)
dotcom-rendering/dist/4688.js 0 B -33.6 kB (removed) 🏆
dotcom-rendering/dist/4813.js 5.3 kB +9 B (0%)
dotcom-rendering/dist/4813.legacy.js 5.4 kB +11 B (0%)
dotcom-rendering/dist/5356.js 5.73 kB +175 B (+3%)
dotcom-rendering/dist/5356.legacy.js 5.91 kB +203 B (+4%)
dotcom-rendering/dist/5585.js 6.71 kB +183 B (+3%)
dotcom-rendering/dist/5585.legacy.js 6.97 kB +208 B (+3%)
dotcom-rendering/dist/6046.js 0 B -4.37 kB (removed) 🏆
dotcom-rendering/dist/6046.legacy.js 0 B -4.44 kB (removed) 🏆
dotcom-rendering/dist/6348.js 5.36 kB +184 B (+4%)
dotcom-rendering/dist/6348.legacy.js 5.55 kB +205 B (+4%)
dotcom-rendering/dist/6965.js 3.2 kB +9 B (0%)
dotcom-rendering/dist/6965.legacy.js 3.26 kB +11 B (0%)
dotcom-rendering/dist/7051.js 7.8 kB +180 B (+2%)
dotcom-rendering/dist/7051.legacy.js 7.98 kB +207 B (+3%)
dotcom-rendering/dist/7262.js 16.6 kB -1.82 kB (-10%) 👏
dotcom-rendering/dist/7262.legacy.js 16.9 kB -1.82 kB (-10%) 👏
dotcom-rendering/dist/7576.js 3.7 kB +378 B (+11%) ⚠️
dotcom-rendering/dist/7576.legacy.js 4.07 kB +397 B (+11%) ⚠️
dotcom-rendering/dist/7583.js 6.05 kB +187 B (+3%)
dotcom-rendering/dist/7583.legacy.js 6.22 kB +204 B (+3%)
dotcom-rendering/dist/77.legacy.js 0 B -29.4 kB (removed) 🏆
dotcom-rendering/dist/7700.js 5.91 kB +198 B (+3%)
dotcom-rendering/dist/7700.legacy.js 6.24 kB +222 B (+4%)
dotcom-rendering/dist/8344.js 6.95 kB +192 B (+3%)
dotcom-rendering/dist/8344.legacy.js 7.3 kB +213 B (+3%)
dotcom-rendering/dist/9641.js 6.69 kB +184 B (+3%)
dotcom-rendering/dist/9641.legacy.js 6.97 kB +209 B (+3%)
dotcom-rendering/dist/9776.js 6.61 kB +183 B (+3%)
dotcom-rendering/dist/9776.legacy.js 6.9 kB +215 B (+3%)
dotcom-rendering/dist/9817.js 11.8 kB +242 B (+2%)
dotcom-rendering/dist/9817.legacy.js 12 kB +276 B (+2%)
dotcom-rendering/dist/frontend.server.js 359 kB +4.37 kB (+1%)
dotcom-rendering/dist/initDiscussion.js 7.99 kB +20 B (0%)
dotcom-rendering/dist/initDiscussion.legacy.js 8.24 kB +21 B (0%)
dotcom-rendering/dist/InteractiveBlockComponent.js 5.93 kB +167 B (+3%)
dotcom-rendering/dist/InteractiveBlockComponent.legacy.js 6.17 kB +190 B (+3%)
dotcom-rendering/dist/islands.js 8.16 kB +21 B (0%)
dotcom-rendering/dist/islands.legacy.js 8.89 kB +20 B (0%)
dotcom-rendering/dist/react.js 61.1 kB +166 B (0%)
dotcom-rendering/dist/react.legacy.js 68.2 kB +151 B (0%)
dotcom-rendering/dist/sentry.js 715 B +38 B (+6%) 🔍
dotcom-rendering/dist/sentry.legacy.js 727 B +38 B (+6%) 🔍
dotcom-rendering/dist/sentryLoader.js 4.85 kB +102 B (+2%)
dotcom-rendering/dist/sentryLoader.legacy.js 7.81 kB +103 B (+1%)
ℹ️ View Unchanged
Filename Size
dotcom-rendering/dist/1214.js 2.65 kB
dotcom-rendering/dist/1214.legacy.js 2.71 kB
dotcom-rendering/dist/1230.js 3.62 kB
dotcom-rendering/dist/1376.js 1.9 kB
dotcom-rendering/dist/1376.legacy.js 2.01 kB
dotcom-rendering/dist/1624.js 2.64 kB
dotcom-rendering/dist/1624.legacy.js 2.71 kB
dotcom-rendering/dist/2.js 4.36 kB
dotcom-rendering/dist/2.legacy.js 4.47 kB
dotcom-rendering/dist/2554.js 2.69 kB
dotcom-rendering/dist/2554.legacy.js 2.71 kB
dotcom-rendering/dist/2947.js 2.58 kB
dotcom-rendering/dist/2947.legacy.js 2.66 kB
dotcom-rendering/dist/3249.js 3.42 kB
dotcom-rendering/dist/3397.js 238 B
dotcom-rendering/dist/3397.legacy.js 250 B
dotcom-rendering/dist/4025.js 1.52 kB
dotcom-rendering/dist/4025.legacy.js 1.55 kB
dotcom-rendering/dist/4211.js 2 kB
dotcom-rendering/dist/4211.legacy.js 2.11 kB
dotcom-rendering/dist/4279.js 4.33 kB
dotcom-rendering/dist/4576.js 234 B
dotcom-rendering/dist/4576.legacy.js 245 B
dotcom-rendering/dist/4850.js 233 B
dotcom-rendering/dist/4850.legacy.js 244 B
dotcom-rendering/dist/5096.js 4.67 kB
dotcom-rendering/dist/5096.legacy.js 4.74 kB
dotcom-rendering/dist/5217.js 232 B
dotcom-rendering/dist/5217.legacy.js 243 B
dotcom-rendering/dist/5226.js 5.22 kB
dotcom-rendering/dist/5226.legacy.js 5.61 kB
dotcom-rendering/dist/53.js 4.11 kB
dotcom-rendering/dist/53.legacy.js 4.12 kB
dotcom-rendering/dist/5310.js 4.53 kB
dotcom-rendering/dist/586.js 4.63 kB
dotcom-rendering/dist/586.legacy.js 4.7 kB
dotcom-rendering/dist/5868.legacy.js 5.79 kB
dotcom-rendering/dist/6222.legacy.js 3.47 kB
dotcom-rendering/dist/6400.js 21.5 kB
dotcom-rendering/dist/6400.legacy.js 21.5 kB
dotcom-rendering/dist/6684.js 239 B
dotcom-rendering/dist/6684.legacy.js 251 B
dotcom-rendering/dist/6992.js 2.02 kB
dotcom-rendering/dist/6992.legacy.js 2.12 kB
dotcom-rendering/dist/7417.legacy.js 5.25 kB
dotcom-rendering/dist/7800.js 11 kB
dotcom-rendering/dist/7912.js 33.6 kB
dotcom-rendering/dist/8080.js 1.81 kB
dotcom-rendering/dist/8080.legacy.js 1.9 kB
dotcom-rendering/dist/8129.legacy.js 11.5 kB
dotcom-rendering/dist/8294.js 231 B
dotcom-rendering/dist/8294.legacy.js 242 B
dotcom-rendering/dist/8748.js 230 B
dotcom-rendering/dist/8748.legacy.js 242 B
dotcom-rendering/dist/8839.js 1.14 kB
dotcom-rendering/dist/8839.legacy.js 1.24 kB
dotcom-rendering/dist/8918.legacy.js 3.77 kB
dotcom-rendering/dist/9078.js 4.36 kB
dotcom-rendering/dist/9078.legacy.js 4.42 kB
dotcom-rendering/dist/92.js 529 B
dotcom-rendering/dist/9311.js 18.5 kB
dotcom-rendering/dist/9327.js 1.86 kB
dotcom-rendering/dist/9327.legacy.js 1.95 kB
dotcom-rendering/dist/9540.legacy.js 29.4 kB
dotcom-rendering/dist/97.legacy.js 20.7 kB
dotcom-rendering/dist/atomIframe.js 1.87 kB
dotcom-rendering/dist/atomIframe.legacy.js 2.14 kB
dotcom-rendering/dist/bootCmp.js 7.31 kB
dotcom-rendering/dist/bootCmp.legacy.js 10.9 kB
dotcom-rendering/dist/braze-web-sdk-core.js 36.1 kB
dotcom-rendering/dist/braze-web-sdk-core.legacy.js 36.1 kB
dotcom-rendering/dist/coreVitals.js 4.03 kB
dotcom-rendering/dist/coreVitals.legacy.js 4.33 kB
dotcom-rendering/dist/dynamicImport.js 3 kB
dotcom-rendering/dist/dynamicImport.legacy.js 3.29 kB
dotcom-rendering/dist/embedIframe.js 1.88 kB
dotcom-rendering/dist/embedIframe.legacy.js 2.14 kB
dotcom-rendering/dist/ga.js 3.88 kB
dotcom-rendering/dist/ga.legacy.js 4.14 kB
dotcom-rendering/dist/guardian-braze-components-banner.js 11.9 kB
dotcom-rendering/dist/guardian-braze-components-banner.legacy.js 12 kB
dotcom-rendering/dist/guardian-braze-components-end-of-article.js 8.11 kB
dotcom-rendering/dist/guardian-braze-components-end-of-article.legacy.js 8.18 kB
dotcom-rendering/dist/newsletterEmbedIframe.js 2.03 kB
dotcom-rendering/dist/newsletterEmbedIframe.legacy.js 2.29 kB
dotcom-rendering/dist/ophan.js 7.18 kB
dotcom-rendering/dist/ophan.legacy.js 7.38 kB
dotcom-rendering/dist/readerRevenueDevUtils.js 892 B
dotcom-rendering/dist/readerRevenueDevUtils.legacy.js 952 B
dotcom-rendering/dist/relativeTime.js 2.41 kB
dotcom-rendering/dist/relativeTime.legacy.js 2.68 kB
dotcom-rendering/dist/shimport.js 2.75 kB
dotcom-rendering/dist/shimport.legacy.js 2.76 kB
dotcom-rendering/dist/SignInGateMain.js 3.56 kB
dotcom-rendering/dist/SignInGateMain.legacy.js 3.69 kB

compressed-size-action

@tomrf1
tomrf1 marked this pull request as ready for review February 23, 2022 14:33
@tomrf1
tomrf1 requested review from a team, JamieB-gu and marsavar as code owners February 23, 2022 14:33
@tomrf1

tomrf1 commented Feb 25, 2022 •

Copy link
Copy Markdown
Member Author

Could we move this code out of App.tsx and down into the respective components? We're about to delete App.tsx and so we don't want to add any more logic to this file.

Wait, what? Deleting App, what?!

There are documents here and here explaining the reasoning and here is a PR introducing Islands, the replacement for App.

So what do I do with my React state?

We moving global state down into local components. This means where you had shared global App state it should be duplicated and moved into the specific components. There are examples of this in other PRs

I'm still confused

It's just confusing. Please do reach out to the team; we're extremely happy to pair on this!

I've now merged in main, which means the AC code is no longer in App.tsx.
I've refactored the getArticleCount function to return both weekly and daily ACs.

export const isNPageOrHigherPageView = (n: number = 2): boolean => {
// get daily read article count array from local storage
const [dailyCount = {} as DailyArticle] = getDailyArticleCount();
const [dailyCount = {} as DailyArticle] = getDailyArticleCount() || [];

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the return type here to DailyArticleHistory | undefined because undefined is a more deliberate signal that there is no article count. This is consistent with the weekly article count.

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.

Just to check thinking here:
undefined = 0? A thought on this is that undefined is also used to indicate that a reader hasn't given consent? Are we happy saying those are the same things?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

getDailyArticleCount returns undefined if there is no article count in local storage, which would be because they haven't consented. On the Supporter Revenue side it's good to be clear about this.
While doing this PR I discovered that the SignInGate (this file) is also using article count - so I've kept the logic the same as before here by defaulting to [].

@tomrf1 tomrf1 changed the title Send today's AC and contentType in banner requests Send today's article count and contentType in banner requests Feb 25, 2022
jamesgorrie
jamesgorrie previously approved these changes Mar 2, 2022
return {
weeklyArticleHistory: window.guardian.weeklyArticleCount,
dailyArticleHistory: window.guardian.dailyArticleCount,
};

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.

Why couple these two and not just use getWeeklyArticleCount and getDailyArticleCount separately as two different pieces of state?

A bit of my confusion is that I would expect, consent isn't given to return undefined, rather than EmptyArticleCounts. Decoupling them might help with confusion.

I can see benefit is we used them together, but we don't seem to anywhere in the code, rather we just destructure this type.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question, I spent a while thinking about this!
The banner does use both counts, and so it's quite convenient to pass them through together (from StickBottomBanner, down a few function calls) here: https://github.com/guardian/dotcom-rendering/pull/3954/files#diff-9fb4db8893a570211b30acefe9224ff36a020986088db2ae69a32dc36723c6e7R235

Also it also felt natural to keep the initialisation of these 2 counts together in this one function because it all depends on awaiting hasOptedOutOfArticleCount.
But - I'm not wedded to this implementation if you think it's preferable to split them?

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.

Sorry, I think I might have conflated things.

I am confused by this method return type as it stands. If someone has not consented, I would expect to get undefined. Instead I get an object with undefined prop values, which feels like they mean that they are available, just not set. So, in my head the return type of ArticleCounts | undefined might make more sense.

Some tests might make this more understandable.

On your point re: async hasOptedOut -> this is true, dotcom could potentially have a better way of sharing this state. Given that that is a potential performance issue, we could just leave it as 1.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah right I see what you mean, I'll have a go at refactoring to return ArticleCounts | undefined

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've just pushed this up

export const isNPageOrHigherPageView = (n: number = 2): boolean => {
// get daily read article count array from local storage
const [dailyCount = {} as DailyArticle] = getDailyArticleCount();
const [dailyCount = {} as DailyArticle] = getDailyArticleCount() || [];

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.

Just to check thinking here:
undefined = 0? A thought on this is that undefined is also used to indicate that a reader hasn't given consent? Are we happy saying those are the same things?

@jamesgorrie
jamesgorrie self-requested a review March 2, 2022 09:44
@jamesgorrie
jamesgorrie dismissed their stale review March 2, 2022 09:44

Shouldn't have been an approval

@jamesgorrie jamesgorrie left a comment

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.

I think this PR surfaces that how we share async state could use some work. I also think it's outside of the scope of this PR.

There's a question on the return type of getArticleCounts.

@tomrf1

tomrf1 commented Mar 3, 2022

Copy link
Copy Markdown
Member Author

getArticleCounts

Thanks for the review! I think I have at least partially addressed the question about getArticleCounts in the last commit

@tomrf1
tomrf1 merged commit 78659dc into main Mar 3, 2022
@tomrf1
tomrf1 deleted the tf-daily-ac branch March 3, 2022 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants