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

feat: Initial Native Ad Support #650

Merged
merged 39 commits into from
Dec 30, 2024
Merged

feat: Initial Native Ad Support #650

merged 39 commits into from
Dec 30, 2024

Conversation

wjaykim
Copy link
Collaborator

@wjaykim wjaykim commented Nov 4, 2024

Description

Initial Native Advanced Ad Support

Detail usage of the API is documented in documentation preview.

References

Concepts

Headless NativeAsset component

Unlike previous RNAdmobNativeAd did, this implementations offers headless NativeAsset component. NativeAsset component is for registering 'asset view' to Native Ad, which allows the SDK to automatically handle tasks such as recording clicks, recording impressions, ... by wrapping the asset view. It does not have UI implementation, so App Developers must implement UI as for their needs. By doing this, we can make app developers customize their complex Native Ad style more easily.

For example:

<NativeAdView
  nativeAd={nativeAd}>
  <View style={{ padding: 16 }}>
    <NativeAsset assetType={'headline'}>
      <Text style={{ fontSize: 18, fontWeight: 'bold' }}>{nativeAd.headline}</Text>
    </NativeAsset>
    <NativeAsset assetType={'body'}>
      <Text>{nativeAd.body}</Text>
    </NativeAsset>
  </View>
  <NativeAsset assetType={'callToAction'}>
    <Text style={{ backgroundColor: '#4285F4', color: 'white', fontWeight: 'bold', padding: 8 }}>{nativeAd.callToAction}</Text>
  </NativeAsset>
</NativeAdView>

SoC for Ad Instance and Ad View

Unlike BannerAd did, I separated process of loading ad and displaying ad respectively. Native Ad is more complex than Banner Ad, because:

  • App developers need to access native assets of the loaded ad
  • Sometimes they want to preload the ad, and display the ad immediately when the need.

Loading native ad, passing nativeAd to NativeAdView as props when available:

const NativeComponent = () => {
  const [nativeAd, setNativeAd] = useState<NativeAd>();

  useEffect(() => {
    NativeAd.createForAdRequest(TestIds.NATIVE)
      .then(setNativeAd)
      .catch(console.error);
  }, []);

   if (!nativeAd) {
    return null;
  }

  return (
    <NativeAdView nativeAd={nativeAd}>
      // Components to display assets must be placed here
    </NativeAdView>
  );
};

Ad instance per request

Unlike FullScreenAds(Interstitial, Rewarded, ...) of our library, ad instance is initialized after the ad is loaded.

By doing this,

  • Loading step is simplified using Promise, replacing event listener
  • Properties of the ad(especially assets of the ad) is guaranteed to be initialized

Supports Both new arch and old arch

This implementation supports both new arch and old arch, while using turbo module and fabric native component codebase.

Related issues

#638

Release Summary

Checklist

  • I read the Contributor Guide
    and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in __tests__e2e__
    • jest tests added or updated in __tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan


Think react-native-google-mobile-ads is great? Please consider supporting the project with any of the below:

  • 👉 Star this repo on GitHub ⭐️
  • 👉 Follow Invertase on Twitter

Copy link

docs-page bot commented Nov 4, 2024

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/react-native-google-mobile-ads~650

Documentation is deployed and generated using docs.page.

@wjaykim wjaykim changed the title [WIP] Native Ad Support feat: [WIP] Native Ad Support Nov 4, 2024
@dylancom
Copy link
Collaborator

dylancom commented Nov 4, 2024

Amazing work so far @wjaykim. So this means you don't have to create a template in Xcode right?

@dylancom dylancom linked an issue Nov 4, 2024 that may be closed by this pull request
@wjaykim
Copy link
Collaborator Author

wjaykim commented Nov 4, 2024

So this means you don't have to create a template in Xcode right?

@dylancom Yes it is. It will work just by writing jsx.

Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

@wjaykim shows up from nowhere after a long time and just drops native ad support 😆

🏆

@AppDeveloperGroup
Copy link

Hello! Tell me how to show advertising images?

@goxr3plus
Copy link

When will this be merged we need it :)

@mikehardy
Copy link
Collaborator

@goxr3plus easy to use patch-package to integrate it, please provide testing and feedback, that is very very useful when it comes to merging PRs. Can't give any ETAs whatsoever (it's open source!) but it is marked as draft, so at least for me, it's not ready. Only @wjaykim can say otherwise since they are the benevolent author that provided the code

@wjaykim wjaykim force-pushed the @wjaykim/native-ad branch 3 times, most recently from 1b39cf8 to 87499ca Compare November 20, 2024 17:11
@goxr3plus
Copy link

goxr3plus commented Nov 20, 2024

@wjaykim You are doing an amazing work i have checked the file changes and the quality is top 🔝. Thank you so much for your effort ♥️ 👑

@wjaykim wjaykim force-pushed the @wjaykim/native-ad branch 2 times, most recently from 21a4c15 to bb35abc Compare November 22, 2024 15:28
@ducpt-bili
Copy link

hi @goxr3plus , may you give me a guide how to patch-package with native ads and using them in your project. Thanks

@goxr3plus
Copy link

hi @goxr3plus , may you give me a guide how to patch-package with native ads and using them in your project. Thanks

I am still waiting it to be on the main branch official, i haven't patched or used this as it's work in progress, probably it's finalized soon ☺️

@Aporial
Copy link

Aporial commented Dec 6, 2024

Is there any way to use it?

@mikehardy
Copy link
Collaborator

mikehardy commented Dec 6, 2024

@Aporial there is but you (or anyone that wants to use it) needs to be careful and know what they are doing, yes? Has to be said :-)

But the tree is visible here:
https://github.com/invertase/react-native-google-mobile-ads/commits/%40wjaykim/native-ad/

The last commit shared with main is
feefff7

So: in your package.json
1- set that main git commit SHA reference as the package reference for this package, it's the last shared commit on main we published, so that is the safe basis
2- download the diff for the PR: https://patch-diff.githubusercontent.com/raw/invertase/react-native-google-mobile-ads/pull/650.diff into "custom-patches" directory in project root
3- add "custom-patch" property to "scripts" in package.json, run as "cd node_modules/react-native-google-mobile-ads && patch -p1 --forward < custom-patches/650.diff || true" so you can use it as a javascript build target
4- add "custom-build" property to "scripts" in package.json, run as "cd node_modules/react-native-google-mobile-ads" && yarn && yarn build"
4- add "postinstall" property to "scripts" in package.json so it runs every time you run yarn (npm people, replace with npm and/or npm -i as needed). Run as "yarn custom-build && yarn custom-patch"

That (or maybe something very similar to that, if the paths in the diffs are wrong in step 3, or if I had a typo somewhere), should get you a published stable commit of main repo, with the PR diff layered on top, if you want to test it and provide feedback

@wjaykim
Copy link
Collaborator Author

wjaykim commented Dec 6, 2024

I'm still working on it, there's still not implemented features(such as controlling video, receiving events...), and also I have to update documentation before I can say it's ready for review. I have no particular motivation for this work, but just for voluntary purposes. And since this is not my main job, it's hard to allocate my resource fully on this PR(especially these year-end days). Sorry to those who are waiting, but �I'm trying to and wish to end-up this PR ASAP, fyi.

@Aporial
Copy link

Aporial commented Dec 6, 2024

If it shows an image, title, description and a button - that's great)

@dylancom dylancom force-pushed the main branch 3 times, most recently from 107d7be to 6c186c7 Compare December 17, 2024 08:14
@Roshdy
Copy link

Roshdy commented Dec 23, 2024

can I donate or pay to complete this feature?

I've already starred and followed you

@wjaykim wjaykim marked this pull request as ready for review December 29, 2024 07:12
@dylancom dylancom requested a review from mikehardy December 29, 2024 13:33
Copy link
Collaborator

@dylancom dylancom left a comment

Choose a reason for hiding this comment

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

@dylancom dylancom changed the title feat: [WIP] Native Ad Support feat: Initial Native Ad Support Dec 29, 2024
README.md Outdated Show resolved Hide resolved
@dylancom
Copy link
Collaborator

dylancom commented Dec 29, 2024

Fantastic work. The last (and most challenging) puzzle piece in completing this package.
Waiting for a review from @mikehardy.

previously was whole line which made scrolling impossible
- use new built-in ccache_enabled property vs custom
- insert ios compile quieting block using new string match
- correctly use patch-package for example patches
- fix touchability / scrollability issues in test app
- use community CLI package to do react-native install, skip git init
- don't set kotlin version to a really old version
this was required on iOS to quiet the warning about insufficient attribution

- increased font size slightly
- decreased padding slightly
not so on android, indeed there you have to implement some methods,
but for iOS it will throw without this
this is the event type we register our listener with, and contains
all the native events
Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

I'm not an expert in the implementation so my comments are shallow there - though I did read through everything and it did look good to me

My main contribution here is to really work through testing it, on new and old architecture on both platforms.

To support this I refreshed the example (and fixed up the script so it is more modern) and committed those changes

Then as I was testing it on old architecture I noticed an issue with the listener addition on iOS and fixed that, as well as an issue with the event emission type, and I fixed that

I committed those changes and pushed them

I left some nitpicks on wording for the docs (which were excellent, IMHO) and I'll just commit those as a batch

If you two are okay with the commits I tacked on, this is ready for merge in my opinion

Should be a squash I think / feat commit tag

Amazing work

docs/native-ads.mdx Outdated Show resolved Hide resolved
docs/native-ads.mdx Outdated Show resolved Hide resolved
docs/native-ads.mdx Outdated Show resolved Hide resolved
docs/native-ads.mdx Outdated Show resolved Hide resolved
docs/native-ads.mdx Outdated Show resolved Hide resolved
docs/native-ads.mdx Outdated Show resolved Hide resolved
docs/native-ads.mdx Outdated Show resolved Hide resolved
GAM_NATIVE: '/6499/example/native',
NATIVE: '',
NATIVE_VIDEO: '',
GAM_APP_OPEN: '/21775744923/example/app-open',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting that the GAM ids were all wrong! But these do check out --> https://developers.google.com/ad-manager/mobile-ads-sdk/android/test-ads

@dylancom dylancom merged commit f68d987 into main Dec 30, 2024
11 checks passed
@dylancom dylancom deleted the @wjaykim/native-ad branch December 30, 2024 17:43
@mikehardy
Copy link
Collaborator

🎉 This PR is included in version 14.8.0 🎉

The release is available on:

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.

Add Admob Native and Native video ad support
9 participants