พารามิเตอร์คำขอเฉพาะเครือข่าย

อะแดปเตอร์เครือข่ายบางประเภทรองรับพารามิเตอร์เพิ่มเติมซึ่งส่งผ่านไปยังอะแดปเตอร์ได้เมื่อมีการสร้างคำขอโฆษณา ส่วนขยายเหล่านี้เรียกว่าส่วนเสริมเครือข่าย

ปลั๊กอินโฆษณาบนอุปกรณ์เคลื่อนที่ของ Google มี API บน Android และ iOS ที่ให้คุณส่งข้อมูลเพิ่มเติมของเครือข่ายไปยังอะแดปเตอร์สื่อกลางได้ ในการดำเนินการนี้ คุณต้องติดตั้ง MediationNetworkExtrasProvider ใน Android และ FLTMediationNetworkExtrasProvider ใน iOS จากนั้นลงทะเบียนการใช้งานผู้ให้บริการเพิ่มเติมด้วยปลั๊กอิน หลังจากนั้น ปลั๊กอินจะใช้รูปแบบดังกล่าวเพื่อส่งผ่านส่วนขยายเครือข่ายต่างๆ เมื่อสร้างคำขอโฆษณาบน Android หรือ iOS

ลงทะเบียน MediationNetworkExtrasProvider ใน Android

สร้างการติดตั้งใช้งาน MediationNetworkExtrasProvider:

class MyMediationNetworkExtrasProvider implements MediationNetworkExtrasProvider {

  @Override
  public Map<Class<? extends MediationExtrasReceiver>, Bundle> getMediationExtras(
      String adUnitId, @Nullable String identifier) {
    // This example passes extras to the AppLovin adapter.
    // This method is called with the ad unit of the associated ad request, and
    // an optional string parameter which comes from the dart ad request object.
    Bundle appLovinBundle = new AppLovinExtras.Builder().setMuteAudio(true).build();
    Map<Class<? extends MediationExtrasReceiver>, Bundle> extras = new HashMap<>();
    extras.put(ApplovinAdapter.class, appLovinBundle);
    // Note: You can pass extras to multiple adapters by adding more entries.
    return extras;
  }
}

จากนั้นให้ลงทะเบียนคีย์กับ GoogleMobileAdsPlugin:

// Register a MediationNetworkExtrasProvider with the plugin.
public class MainActivity extends FlutterActivity {

  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    super.configureFlutterEngine(flutterEngine);

    // Register your MediationNetworkExtrasProvider to provide network extras to ad requests.
    GoogleMobileAdsPlugin.registerMediationNetworkExtrasProvider(
        flutterEngine, new MyMediationNetworkExtrasProvider());
  }
}

คุณสามารถดูส่วนเสริมที่เครือข่ายต่างๆ รองรับและวิธีสร้างในข้อมูลอ้างอิงของ Android สำหรับเครือข่ายที่เฉพาะเจาะจง

ลงทะเบียน FLTMediationNetworkExtrasProvider บน iOS

สร้างการติดตั้งใช้งาน FLTMediationNetworkExtrasProvider:

@implementation MyFLTMediationNetworkExtrasProvider

- (NSArray<id<GADAdNetworkExtras>> *_Nullable)getMediationExtras:(NSString *_Nonnull)adUnitId
                                       mediationExtrasIdentifier:
                                           (NSString *_Nullable)mediationExtrasIdentifier {
  // This example passes extras to the AppLovin adapter.
  // This method is called with the ad unit of the associated ad request, and
  // an optional string parameter which comes from the dart ad request object.
  GADMAdapterAppLovinExtras *appLovinExtras = [[GADMAdapterAppLovinExtras alloc] init];
  appLovinExtras.muteAudio = NO;
  // Note: You can pass extras to multiple adapters by adding more entries.

  return @[ appLovinExtras ];
}
@end

และลงทะเบียนกับ FLTGoogleMobileAdsPlugin:


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];

  // Register your network extras provider if you want to provide
  // network extras to specific ad requests.
  MyFLTMediationNetworkExtrasProvider *networkExtrasProvider =
      [[MyFLTMediationNetworkExtrasProvider alloc] init];
  [FLTGoogleMobileAdsPlugin registerMediationNetworkExtrasProvider:networkExtrasProvider
                                                          registry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

คุณสามารถดูส่วนเสริมที่เครือข่ายต่างๆ รองรับและวิธีสร้างในข้อมูลอ้างอิง iOS สำหรับเครือข่ายที่เฉพาะเจาะจง

ตัวอย่างที่สมบูรณ์ใน GitHub

ตัวอย่างของเราสาธิตวิธีตั้งค่าพารามิเตอร์ที่กำหนดเองบน AppLovin ในการผสานรวม

สื่อกลาง