| 1 | # Tauri Plugin admob |
| 2 | |
| 3 | > For now this is just a copy of [admob-plus](https://github.com/admob-plus/admob-plus) in the future I would like to refactor the code to be more Tauri friendly. |
| 4 | |
| 5 | > The plugin currently only supports android. If you want iOS support, please feel free to create a pull request |
| 6 | |
| 7 | ## How to install |
| 8 | |
| 9 | Since this plugin is yet not published to crates.io or npm registery, we can install it using github link directly. |
| 10 | |
| 11 | 1. Inside your root directory run this command |
| 12 | |
| 13 | ```bash |
| 14 | npm i tauri-plugin-admob-api |
| 15 | ``` |
| 16 | |
| 17 | > You might need to update your tauri version to "2.4.0" or more |
| 18 | |
| 19 | 2. Inside your `src-tauri` directory run this command |
| 20 | |
| 21 | ```bash |
| 22 | cargo add tauri-plugin-admob |
| 23 | ``` |
| 24 | |
| 25 | 3. Since google library uses different Kotlin version than Tauri you may need to add the following compiler |
| 26 | arg: `-Xskip-metadata-version-check` |
| 27 | |
| 28 | ```kotlin |
| 29 | // src-tauri/gen/android/app/build.gradle.kts |
| 30 | kotlinOptions { |
| 31 | // ... |
| 32 | freeCompilerArgs += "-Xskip-metadata-version-check" |
| 33 | } |
| 34 | ``` |
| 35 | |
| 36 | 4. Add your AdMob app ID, as [identified in the AdMob web interface](https://support.google.com/admob/answer/7356431), |
| 37 | to your app's AndroidManifest.xml. |
| 38 | To do so, add a `<meta-data>` tag with `android:name="com.google.android.gms.ads.APPLICATION_ID"`. You can find your |
| 39 | **app ID** in the AdMob web interface. For `android:value`, insert your own AdMob app ID, surrounded by quotation |
| 40 | marks. |
| 41 | |
| 42 | ```xml |
| 43 | <!-- ./src-tauri/gen/android/app/src/main/AndroidManifest.xml --> |
| 44 | <manifest> |
| 45 | <application> |
| 46 | <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 --> |
| 47 | <meta-data |
| 48 | android:name="com.google.android.gms.ads.APPLICATION_ID" |
| 49 | android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/> |
| 50 | <meta-data |
| 51 | android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT" |
| 52 | android:value="true"/> |
| 53 | </application> |
| 54 | </manifest> |
| 55 | ``` |
| 56 | |
| 57 | ## How to use |
| 58 | |
| 59 | ```ts |
| 60 | import { BannerAd } from "tauri-plugin-admob-api"; |
| 61 | |
| 62 | const showBanner = async () => { |
| 63 | const banner = new BannerAd({ |
| 64 | adUnitId: "ca-app-pub-3940256099942544/9214589741", |
| 65 | position: "bottom", |
| 66 | }); |
| 67 | await banner.load(); |
| 68 | await banner.show(); |
| 69 | }; |
| 70 | ``` |
| 71 | |
| 72 | > For more details on how to use it check the documentation of [admob-plus](https://github.com/admob-plus/admob-plus) |