Skip to content

feat(majc): Replace Freestar with MAJC #1421

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

Merged
merged 21 commits into from
Apr 17, 2025

Conversation

mashalifshin
Copy link
Collaborator

@mashalifshin mashalifshin commented Feb 25, 2025

Goals

Integrate the MAJC into Pocket.

To Do:

  • SSR issue in the build (see current CI error)
  • Put new functionality behind a flag
  • Test coverage

To Done:

  • Figure out why I had trouble with the git+ssh package.json urls, and/or start the process to push to mozilla's private npm. I ended up just including the sdk repo's dist folder into node_modules until we can vend via npm
  • Figure out why there are errors referencing dist/core. Ended up removing the dist in the import paths and that resolved this issue for this build (though we'll want to check this again with a proper vend via npm install instead of manually adding the dep)
  • Error after resolving the above, it's a runtime error now. The page loads and is viewable for a moment and then fails with Unhandled Runtime Error TypeError: null is not an object (evaluating 'resolveDispatcher().useState'). This is fixed now, was due to a bundling bug where client-fetch was being required instead of being bundled.
  • New error with integrating latest ads-sdk main at e48e23f. ReferenceError: navigator is not defined. I think this has to do with the new logger code, and perhaps server side rendering when it shouldn't be?
  • Seeing the "jumping" behavior (aka Freestar style 😭) where when I first load the page, the space for the moz ad is not reserved, so when the moz ad starts loading, the content jumps down abruptly to lower down on the page. I'll post a video.

Justin, Luc, and I took a closer look and we think this is the reflow happening based on the allowAds decision which decides whether to show the component or not based on if the user has premium. Looking closely, seems like we have improved on the Freestar behavior as much as we can on our end (when the component loads, it keeps the space it needs without jumping around), so if we want to go further we could perhaps refactor some surrounding Pocket code? Will be curious to see what Joel thinks.

  • Showing a medium rectangle ad format above and below the fold for mobile. I took a crack at it, but it doesn't request different placements when I use browser tools to emulate mobile viewports. Should I be pulling in the useWindowDimensions hook for this?

  • [ ] Seeing a warning when I first start the dev server: Receivedtruefor a non-boolean attributecrossOrigin. If you want to write it to the DOM, pass a string instead: crossOrigin="true" or crossOrigin={value.toString()}`. We poked around enough to realize the warning is coming from somewhere in Pocket, so considering this out of scope for the PR.

  • Nit: @luc-lisi the IntersectionObserver not found in the global namespace; Impressions may not be observed or this message is being shown server-side. doesn't seem necessary to show in the server-side dev logs since that's expected in that env. Can we do a check and not show it if we're server side?

Before you Submit

We have some formatting rules in place to keep things consistent and clean:

  • Your PR title needs to be formatted as type(context): message
  • Your branch name needs to be formatted as type/work-being-done

Valid types are:

  • feat: a new feature - this will trigger a minor release
  • fix: a fix to an existing feature - this will trigger a patch release
  • refactor: refactoring code or UI
  • build: focused solely on the build/deployment stages (npm, webpack, ci, etc/)
  • docs: documentation updates
  • test: updating test suites
  • chore: cleanup and automated tasks
  • project: only valid in the branch name, represents a jumping off point for a project

Sorry, something went wrong.

@mashalifshin
Copy link
Collaborator Author

@justindarc could you take a look at this next iteration whenever you get a moment? I have brought in the latest main from the ads-sdk repo and fixed the import paths as you suggested yesterday, and I am getting a new error now :

Unhandled Runtime Error
TypeError: null is not an object (evaluating 'resolveDispatcher().useState')

Again, not sure if I've missed something in terms of how to integrate this properly, or if there is an underlying bug in the sdk

@justindarc
Copy link

@justindarc could you take a look at this next iteration whenever you get a moment? I have brought in the latest main from the ads-sdk repo and fixed the import paths as you suggested yesterday, and I am getting a new error now :

Unhandled Runtime Error
TypeError: null is not an object (evaluating 'resolveDispatcher().useState')

Again, not sure if I've missed something in terms of how to integrate this properly, or if there is an underlying bug in the sdk

@mashalifshin what version of "react" and "react-dom" is Pocket using?

@mashalifshin
Copy link
Collaborator Author

@mashalifshin what version of "react" and "react-dom" is Pocket using?

Looks like 19.0.0 for both (here)

@mashalifshin mashalifshin force-pushed the feat/ads-sdk-integration-attempt branch from 92f7e9b to 34bbc36 Compare March 11, 2025 20:01
@mashalifshin
Copy link
Collaborator Author

@justindarc I integrated the latest ads-sdk main at e48e23f. We have a new error, hooray!! 🙌 I think this has to do with the new logger code (tho not gonna message Luc today), and perhaps server side rendering when it shouldn't be?

On the client:
Screenshot 2025-03-11 at 12 57 06 PM

In the server-side logs:

Screenshot 2025-03-11 at 12 56 10 PM

Take a look and lmk if anything obvious jumps out at you, and/or if you'd like to 🍐 again on this like last time

@justindarc
Copy link

@mashalifshin I think I see why this is happening. Can you try the code in my PR branch? https://github.com/mozilla-services/ads-sdk/pull/24

@mashalifshin
Copy link
Collaborator Author

mashalifshin commented Mar 13, 2025

@mashalifshin I think I see why this is happening. Can you try the code in my PR branch? mozilla-services/ads-sdk#24

@justindarc @luc-lisi I pulled the latest main (since the branch was merged) and tried it, and it works!!! First MozAd showing on Pocket in local dev!!! 👏 👏 👏

(I do see some potential bugs/warnings/things we might want to to tune, I'll update this PR description with the deets)

@mashalifshin mashalifshin force-pushed the feat/ads-sdk-integration-attempt branch from 6c1fd1a to ab09a03 Compare March 15, 2025 00:24
@collectedmind
Copy link
Collaborator

collectedmind commented Mar 19, 2025

Seeing the "jumping" behavior (aka Freestar style 😭) where when I first load the page, the space for the moz ad is not reserved, so when the moz ad starts loading, the content jumps down abruptly to lower down on the page. I'll post a video.

Yep! These are static pages, and then we do some injection of things on the client (like user, isPremium, etc.) that let's us show/hide ads etc. Couple of options:

  1. we hold this space, then collapse it gracefully if the user is premium (still some thrashing, but we can make it pretty thrashing)
  2. we hold off on the render until we have the relevant information (this kinda breaks the whole purpose of static for SEO)
  3. We do some css trickery so that the render exists in a hidden state and then comes in once we know the users status.
  4. We have a fallback or blank on the ad system so that space is always used

I will play around with it a bit and see what looks nicest.

Showing a medium rectangle ad format above and below the fold for mobile. I took a crack at it, but it doesn't request different placements when I use browser tools to emulate mobile viewports. Should I be pulling in the useWindowDimensions hook for this?

I think we just need to set up some hooks for this to work. We do have that viewport provider ... but full transparency, I dislike it and have wanted to remove it multiple times, I think there is a better way to manage it. I can fiddle with that as well.

Test coverage. I'd love some guidance on where I can add tests for this new stuff.

So we generally rely on snapshot testing for smoke tests on rendered pages... and even more so in the realm of third party integrations (since the assumption is testing is the domain of the library). For this we would really just test that things don't fall to pieces when the lib fails and make sure we have graceful fallbacks. Testing has a long sordid history with Pocket that has been a tale of woe for me that I am happy to share if you are ever interested.

@mashalifshin
Copy link
Collaborator Author

I took a quick look at the snapshots and it seems like we snapshot test at the level of components here? So I saw that Placard has a snapshot, so maybe snapshot testing the content-ads components (BillboardAboveTheFold & co, and/or AdSlot?) would be the way to go? Lmk if that makes sense and/or you have other ideas

Testing has a long sordid history with Pocket that has been a tale of woe for me that I am happy to share if you are ever interested.

I would like to subscribe to Testing Tales of Woe with Joel, lol. Want to 🍐 ? Or can subscribe in Slack of course

@mashalifshin mashalifshin force-pushed the feat/ads-sdk-integration-attempt branch from 48f2977 to 21dc191 Compare March 26, 2025 00:50
@mashalifshin mashalifshin changed the title feat(ads-sdk): attempt to integrate ads-sdk feat(ads-sdk): Replace Freestar with Mozilla Ads Javascript Client Mar 29, 2025
@mashalifshin mashalifshin force-pushed the feat/ads-sdk-integration-attempt branch from 21dc191 to f0ccbff Compare March 29, 2025 02:20
@mashalifshin mashalifshin changed the title feat(ads-sdk): Replace Freestar with Mozilla Ads Javascript Client feat(majc): Replace Freestar with Mozilla Ads Javascript Component Apr 8, 2025
@mashalifshin mashalifshin changed the title feat(majc): Replace Freestar with Mozilla Ads Javascript Component feat(majc): Replace Freestar with MAJC Apr 8, 2025
@mashalifshin mashalifshin force-pushed the feat/ads-sdk-integration-attempt branch from bdcb9a1 to 84d1aab Compare April 8, 2025 22:25
@collectedmind collectedmind force-pushed the feat/ads-sdk-integration-attempt branch from 84d1aab to ea4207a Compare April 14, 2025 22:07
@collectedmind collectedmind marked this pull request as ready for review April 17, 2025 18:05
Copy link

@nzeltzer nzeltzer left a comment

Choose a reason for hiding this comment

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

lgtm

@collectedmind collectedmind merged commit b33b190 into main Apr 17, 2025
14 checks passed
@collectedmind collectedmind deleted the feat/ads-sdk-integration-attempt branch April 17, 2025 19:22
Copy link

🎉 This PR is included in version 1.160.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

None yet

4 participants