Skip to content

Google Mobile and Web Ads integration #286

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

Open
cagbal opened this issue Sep 7, 2022 · 26 comments · Fixed by #3288
Open

Google Mobile and Web Ads integration #286

cagbal opened this issue Sep 7, 2022 · 26 comments · Fixed by #3288
Assignees
Labels
enhancement Improvement/Optimization feature request Suggestion/Request for additional feature platform: mobile Specific to the mobile platform platform: web Specific to the web platform

Comments

@cagbal
Copy link

cagbal commented Sep 7, 2022

Hi Flet team,

This is an extraordinarily beautiful repo for python devs :)

I am just curious do you have any support now or future for Admob?

@FeodorFitsner
Copy link
Contributor

Sure, we could look into that when mobile version of Flet is ready!

@FeodorFitsner FeodorFitsner changed the title Is it possible to run admob? or any plans to support it? Admob integration Sep 7, 2022
@ObiajuluM
Copy link

admob and adsense

@ndonkoHenri
Copy link
Contributor

@FeodorFitsner FeodorFitsner changed the title Admob integration Google Mobile Ads integration Sep 13, 2023
@ndonkoHenri ndonkoHenri added the enhancement Improvement/Optimization label Feb 22, 2024
@ndonkoHenri ndonkoHenri added platform: mobile Specific to the mobile platform feature request Suggestion/Request for additional feature and removed enhancement Improvement/Optimization labels Mar 3, 2024
@ndonkoHenri
Copy link
Contributor

give me code for add ads in flet app

This feature is not yet available, but is on the roadmap.

@zcfrank1st
Copy link

+1

2 similar comments
@zox47
Copy link

zox47 commented Jul 24, 2024

+1

@swax10
Copy link

swax10 commented Aug 5, 2024

+1

@ndonkoHenri ndonkoHenri changed the title Google Mobile Ads integration Google Mobile and Web Ads integration Aug 16, 2024
@ndonkoHenri ndonkoHenri added the platform: web Specific to the web platform label Aug 16, 2024
@zox47
Copy link

zox47 commented Sep 1, 2024

any update?

@Muddassir-Farooq-official

@FeodorFitsner any update

@zox47
Copy link

zox47 commented Sep 23, 2024

@ndonkoHenri any update

@ndonkoHenri
Copy link
Contributor

Mobile Ads is like 90% done (PR).

Waiting on #3345 (WIP) to finalize as mentioned in #3288 (comment).

Please be patient.

@alex-sirod
Copy link

alex-sirod commented Sep 25, 2024

Very Good! I am very happy with this news.
Is this remaining 10% too critical?
in weeks? months? or more time?

@codepython1
Copy link

Any update ?

@AxlBmre
Copy link

AxlBmre commented Nov 4, 2024

I'll say what the others won't and I mean it with all the love in the world: Hurry up, honey sticks!! We needs this, precious!

Here's some good energy to speed up the process: (∩ᄑ_ᄑ)⊃━☆゚*・。*・

@Muddassir-Farooq-official
  • when will this merged?

@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Flet Development Nov 23, 2024
@ndonkoHenri
Copy link
Contributor

ndonkoHenri commented Nov 23, 2024

Install the latest pre and try mobile ads: pip install flet --pre -U

Example

For now, only two types are present: Banner and Interstitial. More types will be coming in the future.

import flet as ft
import flet.ads as ads


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    id_interstitial = (
        "ca-app-pub-3940256099942544/1033173712"
        if page.platform == ft.PagePlatform.ANDROID
        else "ca-app-pub-3940256099942544/4411468910"
    )

    id_banner = (
        "ca-app-pub-3940256099942544/6300978111"
        if page.platform == ft.PagePlatform.ANDROID
        else "ca-app-pub-3940256099942544/2934735716"
    )

    def handle_interstitial_close(e):
        nonlocal iad
        print("InterstitialAd closed")
        page.overlay.remove(e.control)
        page.overlay.append(iad := get_new_interstitial_ad())
        page.update()

    def get_new_interstitial_ad():
        return ads.InterstitialAd(
            unit_id=id_interstitial,
            on_load=lambda e: print("InterstitialAd loaded"),
            on_error=lambda e: print("InterstitialAd error", e.data),
            on_open=lambda e: print("InterstitialAd opened"),
            on_close=handle_interstitial_close,
            on_impression=lambda e: print("InterstitialAd impression"),
            on_click=lambda e: print("InterstitialAd clicked"),
        )

    def display_new_banner_ad():
        page.add(
            ft.Container(
                content=ads.BannerAd(
                    unit_id=id_banner,
                    on_click=lambda e: print("BannerAd clicked"),
                    on_load=lambda e: print("BannerAd loaded"),
                    on_error=lambda e: print("BannerAd error", e.data),
                    on_open=lambda e: print("BannerAd opened"),
                    on_close=lambda e: print("BannerAd closed"),
                    on_impression=lambda e: print("BannerAd impression"),
                    on_will_dismiss=lambda e: print("BannerAd will dismiss"),
                ),
                width=320,
                height=50,
                bgcolor=ft.colors.TRANSPARENT,
            )
        )

    page.overlay.append(iad := get_new_interstitial_ad())
    page.appbar = ft.AppBar(
        adaptive=True,
        title=ft.Text("Mobile Ads Playground"),
        bgcolor=ft.colors.LIGHT_BLUE_300,
    )
    page.add(
        ft.OutlinedButton("Show InterstitialAd", on_click=lambda e: iad.show()),
        ft.OutlinedButton("Show BannerAd", on_click=lambda e: display_new_banner_ad()),
    )


ft.app(main)

I am documenting this at the moment, but for those testing it right now, Interstitial ads can only be shown once. That's why in the example above we created new ones each time.

Feel free to ask any questions.

Reopening this issue as there's still some work to do.

@ndonkoHenri ndonkoHenri reopened this Nov 23, 2024
@github-project-automation github-project-automation bot moved this from ✅ Done to 🆕 New in Flet Development Nov 23, 2024
@ndonkoHenri ndonkoHenri added the enhancement Improvement/Optimization label Nov 23, 2024
@Muddassir-Farooq-official

What about desktop and web?

@AxlBmre
Copy link

AxlBmre commented Nov 26, 2024

Yay! Thank you guys and great job. Can't wait to try it! ٩(◕‿◕。)۶

@jeanluc-BIZIMANA
Copy link

what about web

@Muddassir-Farooq-official

what about web

+1 @ndonkoHenri

@Muddassir-Farooq-official

what about web
Can we run Google AdSense ads via flet web view??? Is it possible @FeodorFitsner @ndonkoHenri

@ndonkoHenri
Copy link
Contributor

Web will investigated when possible.

@AxlBmre
Copy link

AxlBmre commented Dec 10, 2024

Hey guys, so I'm a total newbie (only started learning about all this like 3-4 months ago). Is there a way to test this new feature with an emulator? I ask because I tried using Android Studio and the app either stays stuck on the splash screen or crashes. Without the Ads it works just fine.

@zox47
Copy link

zox47 commented Jan 5, 2025

Hey guys, so I'm a total newbie (only started learning about all this like 3-4 months ago). Is there a way to test this new feature with an emulator? I ask because I tried using Android Studio and the app either stays stuck on the splash screen or crashes. Without the Ads it works just fine.

same problem

@Muddassir-Farooq-official

Web will investigated when possible.

Here it is https://pub.dev/packages/flutter_ad_manager_web

@zox47
Copy link

zox47 commented Mar 31, 2025

Web will investigated when possible.

remove the navigation bar in Android when show ads because the user can Skip the fron the navigation before it end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement/Optimization feature request Suggestion/Request for additional feature platform: mobile Specific to the mobile platform platform: web Specific to the web platform
Projects
Status: 🆕 New
Development

Successfully merging a pull request may close this issue.

14 participants