Skip to content

Commit

Permalink
track when ads are shown
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Oct 10, 2023
1 parent bc2e97e commit 7d8a005
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal class NetworkFirstPlausibleClient(
.post(body)
.build()
suspendCancellableCoroutine { continuation ->
val call = okHttpClient().newCall(request)
val call = okHttpClient.newCall(request)
continuation.invokeOnCancellation {
call.cancel()
}
Expand All @@ -165,7 +165,7 @@ internal class NetworkFirstPlausibleClient(
}
}

private fun okHttpClient(): OkHttpClient {
val okHttpClient: OkHttpClient by lazy {
val session = LanternApp.getSession()
val hTTPAddr = session.hTTPAddr
val uri = URI("http://" + hTTPAddr)
Expand All @@ -174,6 +174,6 @@ internal class NetworkFirstPlausibleClient(
uri.getPort(),
),
)
return OkHttpClient.Builder().proxy(proxy).build()
OkHttpClient.Builder().proxy(proxy).build()
}
}
4 changes: 4 additions & 0 deletions lib/ad_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:clever_ads_solutions/public/MediationManager.dart';
import 'package:flutter/foundation.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:logger/logger.dart';
import 'package:lantern/common/common.dart';
import 'package:lantern/replica/common.dart';

enum AdType { Google, CAS }
Expand Down Expand Up @@ -109,6 +110,8 @@ class AdHelper {
},
onAdShowedFullScreenContent: (ad) {
logger.i('[Ads Manager] Showing Ads');
PlausibleUtils.trackUserAction(
'User shown interstitial ad', googleAttributes);
},
onAdFailedToShowFullScreenContent: (ad, error) {
logger.i(
Expand All @@ -123,6 +126,7 @@ class AdHelper {
);
_interstitialAd = ad;
logger.i('[Ads Manager] to loaded $ad');
PlausibleUtils.trackUserAction('Interstitial ad loaded', googleAttributes)
},
onAdFailedToLoad: (err) {
_failedLoadAttempts++; // increment the count on failure
Expand Down
1 change: 1 addition & 0 deletions lib/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export 'lru_cache.dart';
export 'model.dart';
export 'model_event_channel.dart';
export 'once.dart';
export 'plausible.dart';
export 'session_model.dart';
export 'single_value_subscriber.dart';
export 'ui/audio.dart';
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.0"
plausible_analytics:
dependency: "direct main"
description:
name: plausible_analytics
sha256: be9f0b467d23cd94861737f10101431ad8b7d280dc0c14f7251e0e24655b07fa
url: "https://pub.dev"
source: hosted
version: "0.3.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ dependencies:
flutter_mailer: ^2.0.0
fluttertoast: ^8.2.2

# Analytics
plausible_analytics: ^0.3.0

# Package information
package_info_plus: ^4.1.0

Expand Down

0 comments on commit 7d8a005

Please sign in to comment.