אירועים בהתאמה אישית מאפשרים להוסיף רשימת רשתות בתהליך בחירת רשת לרשת מודעות שהיא לא רשת מודעות נתמכת. כדי לעשות את זה, צריך להטמיע מתאם של אירועים מותאמים אישית ברשת המודעות שרוצים לשלב.
במאגר שלנו ב-GitHub יש פרויקט לדוגמה של אירוע בהתאמה אישית.
דרישות מוקדמות
כדי ליצור אירועים מותאמים אישית, צריך קודם לשלב באפליקציה אחד מהפורמטים הבאים של מודעות:
יצירת אירוע מותאם אישית בממשק המשתמש
קודם צריך ליצור אירוע מותאם אישית בממשק המשתמש של AdMob. אפשר לעיין בהוראות במאמר הוספה של אירוע מותאם אישית.
צריך לספק את הפרטים הבאים:
- שם המחלקה
השם המלא של המחלקה שמטמיעה את המתאם של האירוע המותאם אישית, לדוגמה:
com.google.ads.mediation.sample.customevent.SampleCustomEvent. מומלץ להשתמש במחלקת מתאם אחת לכל הפורמטים של המודעות באירועים מותאמים אישית.- תווית
שם ייחודי שמגדיר את מקור המודעות.
- פרמטר
ארגומנט מחרוזת אופציונלי שמועבר למתאם האירועים בהתאמה אישית.
אתחול המתאם
כש-Google Mobile Ads SDK (Legacy) מופעל,
initialize()
מופעל בכל המתאמים הנתמכים של צד שלישי ובאירועים בהתאמה אישית שהוגדרו לאפליקציה בממשק המשתמש של AdMob. השתמשו בשיטה הזו כדי לבצע את כל ההגדרות או ההפעלות הנדרשות ב-SDK של הצד השלישי שנדרש לאירוע המותאם אישית.
Java
package com.google.ads.mediation.sample.customevent;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.InitializationCompleteCallback;
import com.google.android.gms.ads.mediation.MediationConfiguration;
public class SampleAdNetworkCustomEvent extends Adapter {
private static final String SAMPLE_AD_UNIT_KEY = "parameter";
@Override
public void initialize(Context context,
InitializationCompleteCallback initializationCompleteCallback,
List<MediationConfiguration> mediationConfigurations) {
// This is where you will initialize the SDK that this custom
// event is built for. Upon finishing the SDK initialization,
// call the completion handler with success.
initializationCompleteCallback.onInitializationSucceeded();
}
}
Kotlin
package com.google.ads.mediation.sample.customevent
import com.google.android.gms.ads.mediation.Adapter
import com.google.android.gms.ads.mediation.InitializationCompleteCallback
import com.google.android.gms.ads.mediation.MediationConfiguration
class SampleCustomEvent : Adapter() {
private val SAMPLE_AD_UNIT_KEY = "parameter"
override fun initialize(
context: Context,
initializationCompleteCallback: InitializationCompleteCallback,
mediationConfigurations: List<MediationConfiguration>
) {
// This is where you will initialize the SDK that this custom
// event is built for. Upon finishing the SDK initialization,
// call the completion handler with success.
initializationCompleteCallback.onInitializationSucceeded()
}
}
מספרי גרסאות של דוחות
כל האירועים המותאמים אישית חייבים לדווח ל-Google Mobile Ads SDK (Legacy) גם על הגרסה של מתאם האירועים המותאמים אישית עצמו וגם על הגרסה של ה-SDK של הצד השלישי שאיתו האירוע המותאם אישית מתממשק. הגרסאות מדווחות כאובייקטים מסוג VersionInfo:
Java
package com.google.ads.mediation.sample.customevent;
public class SampleCustomEvent extends Adapter {
@Override
public VersionInfo getVersionInfo() {
String versionString = new VersionInfo(1, 2, 3);
String[] splits = versionString.split("\\.");
if (splits.length >= 4) {
int major = Integer.parseInt(splits[0]);
int minor = Integer.parseInt(splits[1]);
int micro = Integer.parseInt(splits[2]) * 100 + Integer.parseInt(splits[3]);
return new VersionInfo(major, minor, micro);
}
return new VersionInfo(0, 0, 0);
}
@Override
public VersionInfo getSDKVersionInfo() {
String versionString = SampleAdRequest.getSDKVersion();
String[] splits = versionString.split("\\.");
if (splits.length >= 3) {
int major = Integer.parseInt(splits[0]);
int minor = Integer.parseInt(splits[1]);
int micro = Integer.parseInt(splits[2]);
return new VersionInfo(major, minor, micro);
}
return new VersionInfo(0, 0, 0);
}
}
Kotlin
package com.google.ads.mediation.sample.customevent
class SampleCustomEvent : Adapter() {
override fun getVersionInfo(): VersionInfo {
val versionString = VersionInfo(1,2,3).toString()
val splits: List<String> = versionString.split("\\.")
if (splits.count() >= 4) {
val major = splits[0].toInt()
val minor = splits[1].toInt()
val micro = (splits[2].toInt() * 100) + splits[3].toInt()
return VersionInfo(major, minor, micro)
}
return VersionInfo(0, 0, 0)
}
override fun getSDKVersionInfo(): VersionInfo {
val versionString = VersionInfo(1,2,3).toString()
val splits: List<String> = versionString.split("\\.")
if (splits.count() >= 3) {
val major = splits[0].toInt()
val minor = splits[1].toInt()
val micro = splits[2].toInt()
return VersionInfo(major, minor, micro)
}
return VersionInfo(0, 0, 0)
}
}
בקשה להצגת מודעה
כדי לבקש מודעה, צריך לפעול לפי ההוראות הספציפיות לפורמט המודעה: