Skip to content

Commit a1278b6

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
Internal change.
PiperOrigin-RevId: 834913280
1 parent a857c0e commit a1278b6

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

samples/HelloWorld/Assets/Scripts/GoogleMobileAdsConsentController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class GoogleMobileAdsConsentController : MonoBehaviour
1313
{
1414
/// <summary>
1515
/// If true, it is safe to call MobileAds.Initialize() and load Ads.
16+
/// Test
1617
/// </summary>
1718
public bool CanRequestAds => ConsentInformation.CanRequestAds();
1819

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Diagnostics;
3+
using UnityEngine;
4+
5+
namespace GoogleMobileAds.Common
6+
{
7+
/// <summary>
8+
/// A helper class to time an operation and emit an insight with the duration.
9+
/// </summary>
10+
public class InsightTimer
11+
{
12+
private Insight _insight;
13+
private Stopwatch _stopwatch;
14+
15+
/// <summary>
16+
/// Creates an instance of InsightTimer and starts timing.
17+
/// </summary>
18+
/// <param name="insight">The insight to emit when End() is called.</param>
19+
public InsightTimer(Insight insight)
20+
{
21+
_insight = insight;
22+
if (_insight.Tracing == null)
23+
{
24+
_insight.Tracing = new Insight.TracingActivity();
25+
}
26+
_insight.Tracing.HasEnded = false;
27+
_stopwatch = new Stopwatch();
28+
_stopwatch.Start();
29+
}
30+
31+
/// <summary>
32+
/// Stops the timer, calculates the duration, and emits the insight.
33+
/// </summary>
34+
public void End()
35+
{
36+
if (_insight == null || _insight.Tracing == null || _insight.Tracing.HasEnded)
37+
{
38+
return;
39+
}
40+
_stopwatch.Stop();
41+
_insight.Tracing.DurationMillis = _stopwatch.ElapsedMilliseconds;
42+
_insight.Tracing.HasEnded = true;
43+
InsightsEmitter.Instance.Emit(_insight);
44+
}
45+
}
46+
}

source/plugin/Assets/GoogleMobileAds/Common/RcsClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected override bool ValidateCertificate(byte[] certificateData)
3636

3737
// Batching triggers can be overridden by subclasses. We don't need to expose them in Unity
3838
// Editor. If any trigger fires, a batch of items will get sent.
39-
protected virtual int CountThreshold => 20;
40-
protected virtual float TimeThresholdInSeconds => 120.0f;
39+
protected virtual int CountThreshold => 2;
40+
protected virtual float TimeThresholdInSeconds => 10.0f;
4141

4242
// RCS endpoint for reporting. The `e=1` URL parameter defines JSPB encoding.
4343
private const string ProdRcsUrl = "https://pagead2.googlesyndication.com/pagead/ping?e=1";

source/plugin/Assets/GoogleMobileAds/Platforms/Android/MobileAdsClient.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class MobileAdsClient : AndroidJavaProxy, IMobileAdsClient
3232
private readonly IInsightsEmitter _insightsEmitter = InsightsEmitter.Instance;
3333
private readonly ITracer _tracer;
3434
private Action<IInitializationStatusClient> _initCompleteAction;
35+
private InsightTimer _initializationInsightTimer;
3536

3637
private MobileAdsClient() : base(Utils.OnInitializationCompleteListenerClassName) {
3738
_mobileAdsClass = new AndroidJavaClass(Utils.UnityMobileAdsClassName);
@@ -51,6 +52,10 @@ public void Initialize(Action<IInitializationStatusClient> initCompleteAction)
5152
using (_tracer.StartTrace("MobileAdsClient.Initialize"))
5253
{
5354
_initCompleteAction = initCompleteAction;
55+
_initializationInsightTimer = new InsightTimer(new Insight()
56+
{
57+
Name = Insight.CuiName.SdkInitialized
58+
});
5459

5560
Task.Run(() => {
5661
using (_tracer.StartTrace("AttachCurrentThread"))
@@ -71,10 +76,6 @@ public void Initialize(Action<IInitializationStatusClient> initCompleteAction)
7176
}
7277
});
7378
}
74-
_insightsEmitter.Emit(new Insight()
75-
{
76-
Name = Insight.CuiName.SdkInitialized
77-
});
7879
}
7980

8081
public void SetApplicationVolume(float volume)
@@ -175,6 +176,10 @@ public Version GetSDKVersion()
175176

176177
public void onInitializationComplete(AndroidJavaObject initStatus)
177178
{
179+
if (_initializationInsightTimer != null)
180+
{
181+
_initializationInsightTimer.End();
182+
}
178183
if (_initCompleteAction != null) {
179184
IInitializationStatusClient statusClient = new InitializationStatusClient(initStatus);
180185
_initCompleteAction(statusClient);

0 commit comments

Comments
 (0)