Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class GoogleMobileAdsConsentController : MonoBehaviour
{
/// <summary>
/// If true, it is safe to call MobileAds.Initialize() and load Ads.
/// Test
/// </summary>
public bool CanRequestAds => ConsentInformation.CanRequestAds();

Expand Down
46 changes: 46 additions & 0 deletions source/plugin/Assets/GoogleMobileAds/Common/InsightTimer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Diagnostics;
using UnityEngine;

namespace GoogleMobileAds.Common
{
/// <summary>
/// A helper class to time an operation and emit an insight with the duration.
/// </summary>
public class InsightTimer
{
private Insight _insight;
private Stopwatch _stopwatch;

/// <summary>
/// Creates an instance of InsightTimer and starts timing.
/// </summary>
/// <param name="insight">The insight to emit when End() is called.</param>
public InsightTimer(Insight insight)
{
_insight = insight;
if (_insight.Tracing == null)
{
_insight.Tracing = new Insight.TracingActivity();
}
_insight.Tracing.HasEnded = false;
_stopwatch = new Stopwatch();
_stopwatch.Start();
}

/// <summary>
/// Stops the timer, calculates the duration, and emits the insight.
/// </summary>
public void End()
{
if (_insight == null || _insight.Tracing == null || _insight.Tracing.HasEnded)
{
return;
}
_stopwatch.Stop();
_insight.Tracing.DurationMillis = _stopwatch.ElapsedMilliseconds;
_insight.Tracing.HasEnded = true;
InsightsEmitter.Instance.Emit(_insight);
}
}
}
4 changes: 2 additions & 2 deletions source/plugin/Assets/GoogleMobileAds/Common/RcsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected override bool ValidateCertificate(byte[] certificateData)

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

// RCS endpoint for reporting. The `e=1` URL parameter defines JSPB encoding.
private const string ProdRcsUrl = "https://pagead2.googlesyndication.com/pagead/ping?e=1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MobileAdsClient : AndroidJavaProxy, IMobileAdsClient
private readonly IInsightsEmitter _insightsEmitter = InsightsEmitter.Instance;
private readonly ITracer _tracer;
private Action<IInitializationStatusClient> _initCompleteAction;
private InsightTimer _initializationInsightTimer;

private MobileAdsClient() : base(Utils.OnInitializationCompleteListenerClassName) {
_mobileAdsClass = new AndroidJavaClass(Utils.UnityMobileAdsClassName);
Expand All @@ -51,6 +52,10 @@ public void Initialize(Action<IInitializationStatusClient> initCompleteAction)
using (_tracer.StartTrace("MobileAdsClient.Initialize"))
{
_initCompleteAction = initCompleteAction;
_initializationInsightTimer = new InsightTimer(new Insight()
{
Name = Insight.CuiName.SdkInitialized
});

Task.Run(() => {
using (_tracer.StartTrace("AttachCurrentThread"))
Expand All @@ -71,10 +76,6 @@ public void Initialize(Action<IInitializationStatusClient> initCompleteAction)
}
});
}
_insightsEmitter.Emit(new Insight()
{
Name = Insight.CuiName.SdkInitialized
});
}

public void SetApplicationVolume(float volume)
Expand Down Expand Up @@ -175,6 +176,10 @@ public Version GetSDKVersion()

public void onInitializationComplete(AndroidJavaObject initStatus)
{
if (_initializationInsightTimer != null)
{
_initializationInsightTimer.End();
}
if (_initCompleteAction != null) {
IInitializationStatusClient statusClient = new InitializationStatusClient(initStatus);
_initCompleteAction(statusClient);
Expand Down