Skip to content

Commit aaf6700

Browse files
JillSongcopybara-github
authored andcommitted
Updated iLAR guide with code snippets.
PiperOrigin-RevId: 787998500
1 parent 6dddfd3 commit aaf6700

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.gms.snippets;
18+
19+
import android.os.Bundle;
20+
import androidx.annotation.NonNull;
21+
import com.google.android.gms.ads.AdValue;
22+
import com.google.android.gms.ads.AdapterResponseInfo;
23+
import com.google.android.gms.ads.OnPaidEventListener;
24+
import com.google.android.gms.ads.rewarded.RewardedAd;
25+
26+
/** Java code snippets for the developer guide. */
27+
public class ImpressionLevelAdRevenueSnippets {
28+
29+
// [START on_paid_event_listener]
30+
private void setOnPaidEventListener(RewardedAd ad) {
31+
ad.setOnPaidEventListener(
32+
new OnPaidEventListener() {
33+
@Override
34+
public void onPaidEvent(@NonNull AdValue adValue) {
35+
// Extract the impression-level ad revenue data.
36+
long valueMicros = adValue.getValueMicros();
37+
String currencyCode = adValue.getCurrencyCode();
38+
int precision = adValue.getPrecisionType();
39+
40+
// Get the ad unit ID.
41+
String adUnitId = ad.getAdUnitId();
42+
43+
// Extract ad response information.
44+
AdapterResponseInfo loadedAdapterResponseInfo =
45+
ad.getResponseInfo().getLoadedAdapterResponseInfo();
46+
if (loadedAdapterResponseInfo != null) {
47+
String adSourceName = loadedAdapterResponseInfo.getAdSourceName();
48+
String adSourceId = loadedAdapterResponseInfo.getAdSourceId();
49+
String adSourceInstanceName = loadedAdapterResponseInfo.getAdSourceInstanceName();
50+
String adSourceInstanceId = loadedAdapterResponseInfo.getAdSourceInstanceId();
51+
52+
Bundle extras = ad.getResponseInfo().getResponseExtras();
53+
String mediationGroupName = extras.getString("mediation_group_name");
54+
String mediationABTestName = extras.getString("mediation_ab_test_name");
55+
String mediationABTestVariant = extras.getString("mediation_ab_test_variant");
56+
}
57+
}
58+
});
59+
}
60+
// [END on_paid_event_listener]
61+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.gms.snippets
18+
19+
import com.google.android.gms.ads.OnPaidEventListener
20+
import com.google.android.gms.ads.rewarded.RewardedAd
21+
22+
/** Kotlin code snippets for the developer guide. */
23+
class ImpressionLevelAdRevenueSnippets {
24+
25+
// [START on_paid_event_listener]
26+
private fun setOnPaidEventListener(ad: RewardedAd) {
27+
ad.onPaidEventListener = OnPaidEventListener { adValue ->
28+
// Extract the impression-level ad revenue data.
29+
val valueMicros = adValue.valueMicros
30+
val currencyCode = adValue.currencyCode
31+
val precision = adValue.precisionType
32+
33+
// Get the ad unit ID.
34+
val adUnitId = ad.adUnitId
35+
36+
// Extract ad response information.
37+
val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
38+
val adSourceName = loadedAdapterResponseInfo?.adSourceName
39+
val adSourceId = loadedAdapterResponseInfo?.adSourceId
40+
val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
41+
val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
42+
val extras = ad.responseInfo.responseExtras
43+
val mediationGroupName = extras.getString("mediation_group_name")
44+
val mediationABTestName = extras.getString("mediation_ab_test_name")
45+
val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
46+
}
47+
}
48+
// [END on_paid_event_listener]
49+
}

0 commit comments

Comments
 (0)