From 7d8a005006ec15b8ce61661223c7a47c2af3798e Mon Sep 17 00:00:00 2001 From: atavism Date: Tue, 10 Oct 2023 08:18:08 -0700 Subject: [PATCH] track when ads are shown --- .../org/getlantern/lantern/plausible/PlausibleClient.kt | 6 +++--- lib/ad_helper.dart | 4 ++++ lib/common/common.dart | 1 + pubspec.lock | 8 ++++++++ pubspec.yaml | 3 +++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/org/getlantern/lantern/plausible/PlausibleClient.kt b/android/app/src/main/kotlin/org/getlantern/lantern/plausible/PlausibleClient.kt index 53dfe7412..a97f56b8a 100644 --- a/android/app/src/main/kotlin/org/getlantern/lantern/plausible/PlausibleClient.kt +++ b/android/app/src/main/kotlin/org/getlantern/lantern/plausible/PlausibleClient.kt @@ -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() } @@ -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) @@ -174,6 +174,6 @@ internal class NetworkFirstPlausibleClient( uri.getPort(), ), ) - return OkHttpClient.Builder().proxy(proxy).build() + OkHttpClient.Builder().proxy(proxy).build() } } diff --git a/lib/ad_helper.dart b/lib/ad_helper.dart index c9b6f12e4..a3284eccf 100644 --- a/lib/ad_helper.dart +++ b/lib/ad_helper.dart @@ -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 } @@ -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( @@ -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 diff --git a/lib/common/common.dart b/lib/common/common.dart index 64a1b3506..f304fc8b9 100644 --- a/lib/common/common.dart +++ b/lib/common/common.dart @@ -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'; diff --git a/pubspec.lock b/pubspec.lock index 16831dac9..440b81fd2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 2192591fa..2fb5be89f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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