Skip to content

Commit

Permalink
Update Google Mobile Ads SDK 10.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrovic committed Oct 14, 2023
1 parent 1ccc4ff commit a943c96
Show file tree
Hide file tree
Showing 506 changed files with 83,951 additions and 4,003 deletions.
18 changes: 18 additions & 0 deletions apidoc/Admob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,24 @@ methods:
type: Callback<LoadFormObject>
summary: async callback called when retrieved

- name: isGDPR
returns:
type: Boolean
summary: Check in the IABTCF string if GDPR applies, so if in EEA.
platforms: [iphone]

- name: canShowAds
returns:
type: Boolean
summary: Check in the IABTCF string if user granted at least minimum requirements to show ads.
platforms: [iphone]

- name: canShowPersonalizedAds
returns:
type: Boolean
summary: Check in the IABTCF string if user granted at least minimum requirements to show Personalized ads.
platforms: [iphone]

- name: requestConsentInfoUpdateForPublisherIdentifiers
returns:
type: void
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/TiAdmobModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

- (void)loadForm:(id)args;

- (NSNumber *)isGDPR:(id)unused;

- (NSNumber *)canShowAds:(id)unused;

- (NSNumber *)canShowPersonalizedAds:(id)unused;

- (void)requestConsentInfoUpdateForPublisherIdentifiers:(id)args; // REMOVED

- (void)showConsentForm:(id)args; // REMOVED
Expand Down
83 changes: 81 additions & 2 deletions ios/Classes/TiAdmobModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,85 @@ - (void)requestConsentInfoUpdateForPublisherIdentifiers:(id)args
*/
}

/**
* This functions check if the user has granted the minimum requirements to be able to view the ads,
* (https://support.google.com/admob/answer/9760862?ref_topic=10303737) and if he has chosen to see
* personalized or non-personalized ones.
*
* Inspired by https://stackoverflow.com/questions/65351543/how-to-implement-ump-sdk-correctly-for-eu-consent/68310602#68310602
*/

- (NSNumber *)isGDPR:(id)unused
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSInteger gdpr = [settings integerForKey:@"IABTCF_gdprApplies"];
return @(gdpr == 1);
}

- (NSNumber *)canShowAds:(id)unused
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];

NSString *purposeConsent = [settings stringForKey:@"IABTCF_PurposeConsents"] ?: @"";
NSString *vendorConsent = [settings stringForKey:@"IABTCF_VendorConsents"] ?: @"";
NSString *vendorLI = [settings stringForKey:@"IABTCF_VendorLegitimateInterests"] ?: @"";
NSString *purposeLI = [settings stringForKey:@"IABTCF_PurposeLegitimateInterests"] ?: @"";

NSInteger googleId = 755;
BOOL hasGoogleVendorConsent = [self hasAttribute:vendorConsent atIndex:googleId];
BOOL hasGoogleVendorLI = [self hasAttribute:vendorLI atIndex:googleId];

return @([self hasConsentFor:@[@(1)] purposeConsent:purposeConsent hasVendorConsent:hasGoogleVendorConsent]
&& [self hasConsentOrLegitimateInterestFor:@[@(2), @(7), @(9), @(10)] purposeConsent:purposeConsent purposeLI:purposeLI hasVendorConsent:hasGoogleVendorConsent hasVendorLI:hasGoogleVendorLI]);
}

- (NSNumber *)canShowPersonalizedAds:(id)unused
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];

NSString *purposeConsent = [settings stringForKey:@"IABTCF_PurposeConsents"] ?: @"";
NSString *vendorConsent = [settings stringForKey:@"IABTCF_VendorConsents"] ?: @"";
NSString *vendorLI = [settings stringForKey:@"IABTCF_VendorLegitimateInterests"] ?: @"";
NSString *purposeLI = [settings stringForKey:@"IABTCF_PurposeLegitimateInterests"] ?: @"";

NSInteger googleId = 755;
BOOL hasGoogleVendorConsent = [self hasAttribute:vendorConsent atIndex:googleId];
BOOL hasGoogleVendorLI = [self hasAttribute:vendorLI atIndex:googleId];

return @([self hasConsentFor:@[@(1), @(3), @(4)] purposeConsent:purposeConsent hasVendorConsent:hasGoogleVendorConsent]
&& [self hasConsentOrLegitimateInterestFor:@[@(2), @(7), @(9), @(10)] purposeConsent:purposeConsent purposeLI:purposeLI hasVendorConsent:hasGoogleVendorConsent hasVendorLI:hasGoogleVendorLI]);
}

- (BOOL)hasAttribute:(NSString *)input atIndex:(NSInteger)index
{
return input.length >= index && [[input substringWithRange:NSMakeRange(index - 1, 1)] isEqualToString:@"1"];
}

- (BOOL)hasConsentFor:(NSArray *)purposes purposeConsent:(NSString *)purposeConsent hasVendorConsent:(BOOL)hasVendorConsent
{
for (NSNumber *purpose in purposes) {
NSInteger i = [purpose integerValue];
if (![self hasAttribute:purposeConsent atIndex:i]) {
return NO;
}
}
return hasVendorConsent;
}

- (BOOL)hasConsentOrLegitimateInterestFor:(NSArray *)purposes purposeConsent:(NSString *)purposeConsent purposeLI:(NSString *)purposeLI hasVendorConsent:(BOOL)hasVendorConsent hasVendorLI:(BOOL)hasVendorLI
{
for (NSNumber *purpose in purposes) {
NSInteger i = [purpose integerValue];
if (([self hasAttribute:purposeLI atIndex:i] && hasVendorLI) ||
([self hasAttribute:purposeConsent atIndex:i] && hasVendorConsent)) {
continue;
} else {
return NO;
}
}
return YES;
}

- (void)showConsentForm:(id)args
{
DEPRECATED_REMOVED(@"Admob.showConsentForm", @"5.0.0", @"5.0.0 (Removed since Ti.Admob 5.0.0 in favor of new UMP method Admob.requestConsentInfoUpdateWithParameters())");
Expand Down Expand Up @@ -374,11 +453,11 @@ - (void)setInMobi_updateGDPRConsent:(id)updateGDPRConsent
if ([TiUtils boolValue:updateGDPRConsent]) {
// this method is required by InMobi to set GDPR
[consentObject setObject:@"1" forKey:@"gdpr"];
[consentObject setObject:@"true" forKey:IM_GDPR_CONSENT_AVAILABLE];
[consentObject setObject:@"true" forKey:IMCommonConstants.IM_GDPR_CONSENT_AVAILABLE];
NSLog(@"[DEBUG] Ti.AdMob: inMobi_updateGDPRConsent --> true");
} else {
[consentObject setObject:@"0" forKey:@"gdpr"];
[consentObject setObject:@"true" forKey:IM_GDPR_CONSENT_AVAILABLE];
[consentObject setObject:@"true" forKey:IMCommonConstants.IM_GDPR_CONSENT_AVAILABLE];
NSLog(@"[DEBUG] Ti.AdMob: inMobi_updateGDPRConsent --> false");
}

Expand Down
24 changes: 24 additions & 0 deletions ios/Classes/TiAdmobModuleAssets.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This is a generated file. Do not edit or your changes will be lost
*/
#import "TiAdmobModuleAssets.h"

extern NSData* filterDataInRange(NSData* thedata, NSRange range);

@implementation TiAdmobModuleAssets

- (NSData *)moduleAsset
{


return nil;
}

- (NSData *)resolveModuleAsset:(NSString *)path
{


return nil;
}

@end
3 changes: 1 addition & 2 deletions ios/admob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -73,7 +73,6 @@
5E6743A427F4B84500BEE594 /* WebKit.framework in Frameworks */,
5E343CDF291BFA3600F047EB /* MetaAdapter.xcframework in Frameworks */,
5ED7B66026EBC395007F4D90 /* FBAudienceNetwork.xcframework in Frameworks */,

5EFC8F50263ABC430011A0C2 /* InMobiSDK.xcframework in Frameworks */,
5EFC8F51263ABC430011A0C2 /* InMobiAdapter.xcframework in Frameworks */,
3ABFE38E26335E0000887180 /* nanopb.xcframework in Frameworks */,
Expand Down
10 changes: 10 additions & 0 deletions ios/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

### v6.3.0
- Added iphone methods `isGDPR()`, `canShowAds()`, `(canShowPersonalizedAds)`
- Update Google Mobile Ads SDK 10.12.0 (https://github.com/CocoaPods/Specs/tree/master/Specs/5/9/a/Google-Mobile-Ads-SDK/10.12.0)
- Update Meta Audience Network SDK 6.14.0 (https://developers.facebook.com/docs/audience-network/setting-up/platform-setup/ios/changelog#6_14_0)
- Update Meta Adapter 6.14.0.0 (https://developers.google.com/admob/ios/mediation/meta#version-6.14.0.0)
- Update InMobi SDK 10.1.3 (https://support.inmobi.com/monetize/sdk-documentation/download-sdk)
- Update InMobiAdapter 10.5.8.0 (https://developers.google.com/admob/ios/mediation/inmobi#version-10.5.8.0)
- Updated documentation and iOS example


### v6.2.0
- Added support for App Open Ad (https://developers.google.com/admob/ios/app-open)
- Reset TC string if last updated date was more than 13 months ago (https://developers.google.com/admob/ios/privacy/gdpr#troubleshooting)
Expand Down
33 changes: 32 additions & 1 deletion ios/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ The module uses these two methods to be able to use it:

In the [app.js](/ios/example/app.js) there is a complete example to better understand how to use them.

### User Consent and Ad serving

**If consent is denied, or if certain values are not checked in the consent management phase, the ads will not be loaded**.

Why does this happen? If you pay attention to the **ConsentStatus.OBTAINED** field, you will notice that it says that **the consent is obtained, but the personalization is not defined**. As you see [here](https://itnext.io/android-admob-consent-with-ump-personalized-or-non-personalized-ads-in-eea-3592e192ec90).

It is up to us developers to check if the user has granted the [**minimum requirements**](https://support.google.com/admob/answer/9760862?ref_topic=10303737) to be able to view the ads, and if he has chosen to see personalized or non-personalized ones.

In order to assist you with this, [Mirko Dimartino](https://mirko-ddd.medium.com/?source=post_page-----3592e192ec90--------------------------------) created a solution inspired on [Tyler V](https://stackoverflow.com/questions/65351543/how-to-implement-ump-sdk-correctly-for-eu-consent/68310602#68310602) that I have implemented in this module thanks to [deckameron](https://github.com/deckameron).

### Mediation adapters

Expand Down Expand Up @@ -185,6 +194,29 @@ To check if a form is available, use the callback status parameter
- `callback` (Function)
Async callback function that return `{status: Modules.Admob.CONSENT_STATUS_*}`

### `isGDPR()` (Boolean)

Check in the IABTCF string if GDPR applies, so if in EEA.

### `canShowAds()` (Boolean)

If false (and GDPR applies, so if in EEA) you should prompt the user or to accept all, or explain in details (check above) what to check to display at least Non-Personalized Ads, or ask the user to opt for a premium version of the app, otherwise you will earn absolutely nothing.

If true you can check if user granted at least minimum requirements to show Personalized Ads with the following method.

### `canShowPersonalizedAds` (Boolean)

Finally you know if you can request AdMob Personalized or Non-Personalized Ads, if Non-Personalized you have to forward the request using this snippet.

```js
var Admob = require('ti.admob');

var ad = Admob.createView({
// your properties...
extras: { 'npa': "1"}, // npa=1 disables personalized ads
});
```

### `requestConsentInfoUpdateWithParameters(args)`

Request the latest consent information.
Expand Down Expand Up @@ -612,7 +644,6 @@ If you are also using [Titanium Firebase Core Module](https://github.com/hansema
`GoogleAppMeasurementIdentitySupport.xcframework`
`GoogleUtilities.xcframework`
`nanopb.xcframework`
`PromisesObjC.xcframework`

## Usage

Expand Down
11 changes: 10 additions & 1 deletion ios/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ function requestConsent() {
}
// If the status is "obtained" (freshly granted) or not required (already granted) continue
if ([Admob.CONSENT_STATUS_NOT_REQUIRED, Admob.CONSENT_STATUS_OBTAINED].includes(e.status)) {
openTestAdsWin();
if (Admob.canShowAds()){
openTestAdsWin();
} else {
alert('You have not granted at least the minimum requirements to show ads!' +
'No fear! You can buy an in-app purchase to use the app without ads :)');
}
} else {
alert('Not ready to show ads! Status = ' + e.status);
}
Expand Down Expand Up @@ -250,6 +255,7 @@ function openTestAdsWin() {
contentURL: 'https://admob.com', // URL string for a webpage whose content matches the app content.
requestAgent: 'Titanium Mobile App', // String that identifies the ad request's origin.
extras: {
'npa': !Admob.canShowPersonalizedAds(),
'version': 1.0,
'name': 'My App'
}, // Object of additional infos
Expand Down Expand Up @@ -289,6 +295,7 @@ function openTestAdsWin() {
adUnitId: 'ca-app-pub-3940256099942544/4411468910', // You can get your own at http: //www.admob.com/
keywords: ['keyword1', 'keyword2'],
extras: {
'npa': !Admob.canShowPersonalizedAds(),
'version': 1.0,
'name': 'My App'
}, // Object of additional infos
Expand Down Expand Up @@ -352,6 +359,7 @@ function openTestAdsWin() {
adType: Admob.AD_TYPE_REWARDED_VIDEO,
adUnitId: 'ca-app-pub-3940256099942544/1712485313',
extras: {
'npa': !Admob.canShowPersonalizedAds(),
'version': 1.0,
'name': 'My App'
} // Object of additional infos
Expand Down Expand Up @@ -442,6 +450,7 @@ function openTestAdsWin() {
adType: Admob.AD_TYPE_APP_OPEN,
adUnitId: 'ca-app-pub-3940256099942544/5662855259', // You can get your own at http: //www.admob.com/
extras: {
'npa': !Admob.canShowPersonalizedAds(),
'version': 1.0,
'name': 'My App'
} // Object of additional infos
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 6.2.0
version: 6.3.0
architectures: arm64 x86_64
mac: false
description: AdMob module for ad delivery via AdMob
Expand Down
11 changes: 5 additions & 6 deletions ios/platform/FBAudienceNetwork.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_armv7</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>FBAudienceNetwork.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>armv7</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>FBAudienceNetwork.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

/***
* This is a bridge file for Audience Network Unity SDK.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

/***
* This is a bridge file for Audience Network Unity SDK.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <UIKit/UIKit.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
Expand Down
Loading

0 comments on commit a943c96

Please sign in to comment.