টিউটোরিয়াল: AdMob বিজ্ঞাপন ফ্রিকোয়েন্সি অপ্টিমাইজ করুন

ধাপ 3: আপনার অ্যাপের কোডে Remote Config প্যারামিটার মানগুলি পরিচালনা করুন



শেষ ধাপের শেষে, আপনি একটি Remote Config প্যারামিটার তৈরি করেছেন ( INTERSTITIAL_AD_KEY )। এই ধাপে, সেই প্যারামিটারের মানের উপর ভিত্তি করে আপনার অ্যাপটি কী প্রদর্শন করবে তার জন্য আপনি আপনার অ্যাপের কোডে যুক্তি যোগ করবেন।

প্রয়োজনীয় SDK যোগ করুন

আপনার অ্যাপ্লিকেশন কোডে Remote Config ব্যবহার করার আগে, আপনার প্রোজেক্ট বিল্ড ফাইলগুলিতে Google Analytics জন্য Remote Config SDK এবং Firebase SDK উভয়ই যোগ করুন।

আপনার পডফাইলে নিম্নলিখিত পড যোগ করুন এবং ইনস্টল করুন:

pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'

আপনার পডফাইলে নিম্নলিখিত পড যোগ করুন এবং ইনস্টল করুন:

pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'

আপনার build.gradle ফাইলে নিম্নলিখিত লাইব্রেরি নির্ভরতা যোগ করুন:

implementation 'com.google.android.gms:play-services-ads:24.0.0'
implementation 'com.google.firebase:firebase-analytics:22.3.0'
implementation 'com.google.firebase:firebase-config:22.1.0'

Firebase ইউনিটি SDK ডাউনলোড এবং ইনস্টল করুন, তারপর আপনার প্রকল্পে নিম্নলিখিত ইউনিটি প্যাকেজগুলি যোগ করুন:

  • FirebaseAnalytics.unitypackage
  • FirebaseRemoteConfig.unitypackage

Remote Config উদাহরণ কনফিগার করুন

Remote Config প্যারামিটার মানগুলি ব্যবহার করতে, Remote Config ইনস্ট্যান্স কনফিগার করুন যাতে এটি ক্লায়েন্ট অ্যাপের উদাহরণের জন্য নতুন মান আনতে সেট আপ হয়।

এই উদাহরণে, Remote Config প্রতি ঘন্টায় একবার নতুন প্যারামিটার মান পরীক্ষা করার জন্য কনফিগার করা হয়েছে।

remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings
self.remoteConfig = [FIRRemoteConfig remoteConfig];
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] init];
remoteConfigSettings.minimumFetchInterval = 3600;
self.remoteConfig.configSettings = remoteConfigSettings;
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
        .setMinimumFetchIntervalInSeconds(3600)
        .build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
    minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)
var remoteConfig = FirebaseRemoteConfig.DefaultInstance;
var configSettings = new ConfigSettings {
  MinimumFetchInternalInMilliseconds =
        (ulong)(new TimeSpan(1, 0, 0).TotalMilliseconds)
};
remoteConfig.SetConfigSettingsAsync(configSettings)
        .ContinueWithOnMainThread(task => {
          Debug.Log("Config settings confirmed");
}

Remote Config আনুন এবং সক্রিয় করুন

Remote Config প্যারামিটার আনুন এবং সক্রিয় করুন যাতে এটি নতুন প্যারামিটার মান ব্যবহার করা শুরু করতে পারে।

আপনি আপনার অ্যাপের লোডিং পর্যায়ে যত তাড়াতাড়ি সম্ভব এই কলটি করতে চাইবেন কারণ এই কলটি অ্যাসিঙ্ক্রোনাস এবং আপনার Remote Config মানটি আগে থেকে আনতে হবে যাতে আপনার অ্যাপটি জানতে পারে কোন বিজ্ঞাপনটি দেখানো হবে৷

remoteConfig.fetch() { (status, error) -> Void in
  if status == .success {
    print("Config fetched!")
    self.remoteConfig.activate() { (changed, error) in
      // ...
    }
  } else {
    print("Config not fetched")
    print("Error: \(error?.localizedDescription ?? "No error available.")")
  }
  self.loadAdUnit()
}
[self.remoteConfig fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {
    if (status == FIRRemoteConfigFetchStatusSuccess) {
        NSLog(@"Config fetched!");
      [self.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) {
        // ...
      }];
    } else {
        NSLog(@"Config not fetched");
        NSLog(@"Error %@", error.localizedDescription);
    }
    [self loadAdUnit];
}];
mFirebaseRemoteConfig.fetchAndActivate()
        .addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
            @Override
            public void onComplete(@NonNull Task<Boolean> task) {
                if (task.isSuccessful()) {
                    boolean updated = task.getResult();
                    Log.d(TAG, "Config params updated: " + updated);
                } else {
                    Log.d(TAG, "Config params failed to update");
                }
                loadAdUnit();
            }
        });
remoteConfig.fetchAndActivate()
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                val updated = task.result
                Log.d(TAG, "Config params updated: $updated")
            } else {
                Log.d(TAG, "Config params failed to update")
            }
            loadAdUnit()
        }
remoteConfig.FetchAndActivateAsync().ContinueWithOnMainThread(task => {
  if (task.IsFaulted) {
    Debug.LogWarning("Config params failed to update");
  } else {
    Debug.Log("Config params updated: " + task.Result);
  }
  LoadAdUnit();
});

আপনার অ্যাপ এখন এই টিউটোরিয়ালের আগে সেট আপ করা A/B পরীক্ষার সময় তৈরি করা Remote Config প্যারামিটারটি পরিচালনা করার জন্য প্রস্তুত।

Remote Config প্যারামিটার মান ব্যবহার করুন

এই অ্যাপ ইন্সট্যান্সের জন্য কোন বিজ্ঞাপন ফ্রিকোয়েন্সি ভেরিয়েন্ট দেখানো হবে তা নির্ধারণ করতে loadAdUnit() ফাংশনে প্রি-ফেচ করা Remote Config মান ব্যবহার করুন।

private func loadAdUnit() {
  let adUnitId = remoteConfig["INTERSTITIAL_AD_KEY"].stringValue;
  let request = GADRequest()
  GADInterstitialAd.load(withAdUnitID: adUnitId,
                               request: request,
                     completionHandler: { [self] ad, error in
                       if let error = error {
                         print("Failed to load: \(error.localizedDescription)")
                         return
                       }
                       interstitial = ad
                       // Register for callbacks.
                     }
  )
}

// Register for callbacks.
- (void)loadAdUnit {
    NSString *adUnitId =
      self.remoteConfig[@"INTERSTITIAL_AD_KEY"].stringValue;

  GADRequest *request = [GADRequest request];
  [GADInterstitialAd loadAdWithAdUnitId:adUnitId
                         request:request
                         completionHandler:^(GADInterstitialAd *ad,
                             NSError *error) {
    if (error) {
      NSLog(@"Failed to load interstitial ad with error: %@",
        [error localizedDescription]);
      return;
    }

    self.interstitial = ad;
  }];
}
private void loadAdUnit() {
    String adUnitId =
      mFirebaseRemoteConfig.getString("INTERSTITIAL_AD_KEY");

    // Load Interstitial Ad (assume adUnitId not null)
    AdRequest adRequest = new AdRequest.Builder().build();

    InterstitialAd.load(this, adUnitId, adRequest, new
        InterstitialAdLoadCallback() {
          @Override
          public void onAdLoaded(@NonNull InterstitialAd intertitialAd) {
            mInterstitialAd = interstitialAd;
          }

          @Override
          public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            mInterstitialAd = null;
          }
    });
}
private fun loadAdUnit() {
  String adUnitId = remoteConfig.getString("INTERSTITIAL_AD_KEY")
  var adRequest = AdRequestBuilder.Builder().build()

  AdRequestBuilder.load(this, adUnitId, adRequest, object :
    InterstitialAdLoadCallback() {
      override fun onAdFailedToLoad(adError: LoadAdError) {
        mInterstitialAd = null
      }

      override fun onAdLoaded(interstitialAd: InterstitialAd) {
        mInterstitialAd = interstitialAd
      }
    })
}
void LoadAdUnit() {

  // Note that you may want to encode and parse two sets of ad unit IDs for
  // Android / iOS in the Unity implementation.
  String adUnitId = remoteConfig.GetValue("INTERSTITIAL_AD_KEY").StringValue;
  this.interstitial = new InterstitialAd(adUnitId);
}

পরামিতি মান জন্য অন্যান্য চেক যোগ করুন

আপনার অ্যাপ্লিকেশন কোডের অন্যান্য ক্ষেত্র রয়েছে যেখানে কোন বিজ্ঞাপন অভিজ্ঞতা লোড হবে তা নির্দেশ করতে আপনাকে এই Remote Config প্যারামিটারের মান পরীক্ষা করতে হবে। উদাহরণস্বরূপ, ব্যবহারকারী বর্তমানটি দেখা শেষ করার পরে আপনি একটি বিজ্ঞাপন পুনরায় লোড করবেন কিনা তা নির্ধারণ করতে পারেন৷

যেকোনো প্যারামিটার মান পরিবর্তনের জন্য কল আনতে এবং সক্রিয় করতে প্রথমে করা উচিত — উদাহরণস্বরূপ, আপনি যদি একটি নতুন পরীক্ষা শেষ করার বা তৈরি করার সিদ্ধান্ত নেন।

সেখান থেকে, আপনি সর্বদা নিম্নলিখিত কলগুলি ব্যবহার করে প্যারামিটারের মান পরীক্ষা করতে পারেন:

remoteConfig["INTERSTITIAL_AD_KEY"].stringValue
self.remoteConfig[@"INTERSTITIAL_AD_KEY"].stringValue;
mFirebaseRemoteConfig.getString(INTERSTITIAL_AD_KEY)
remoteConfig.getString(INTERSTITIAL_AD_KEY)
remoteConfig.GetValue("INTERSTITIAL_AD_KEY").StringValue

এই কলগুলি সর্বদা একটি অ্যাপ ইন্সট্যান্সের জন্য একই মান ফেরত দেবে তা নির্ভর করে এটি নিয়ন্ত্রণ গোষ্ঠীতে বা নতুন বিজ্ঞাপন ভেরিয়েন্ট গ্রুপগুলির মধ্যে একটিতে রাখা হয়েছে, যদি না পূর্বের কলগুলিতে আনা এবং সক্রিয় করা Firebase কনসোলে কোনো পরিবর্তন করা না হয়।




ধাপ 2 : Firebase কনসোলে একটি A/B পরীক্ষা সেট আপ করুন ধাপ 4 : A/B পরীক্ষা শুরু করুন এবং পরীক্ষার ফলাফল পর্যালোচনা করুন