Skip to content

Commit cce284a

Browse files
authored
Merge pull request #2962 from numbersprotocol/fix-v230725-appsflyer-after-capacitor-5-migration
Fix v230725 appsflyer after capacitor 5 migration
2 parents 5cdb5f0 + 2dc3dbf commit cce284a

File tree

5 files changed

+39
-44
lines changed

5 files changed

+39
-44
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
34

45
<!-- Permissions -->
56

@@ -41,6 +42,9 @@
4142
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
4243
<!-- For in-app purchases -->
4344
<uses-permission android:name="com.android.vending.BILLING" />
45+
<!-- https://dev.appsflyer.com/hc/docs/install-android-sdk#revoking-the-ad_id-permission -->
46+
<uses-permission android:name="com.google.android.gms.permission.AD_ID"
47+
tools:node="remove"/>
4448

4549

4650
<queries>

ios/App/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PODS:
1818
- Capacitor
1919
- CapacitorClipboard (5.0.4):
2020
- Capacitor
21-
- CapacitorCommunityAdvertisingId (1.0.0):
21+
- CapacitorCommunityAdvertisingId (5.0.0):
2222
- Capacitor
2323
- CapacitorCommunityBluetoothLe (2.2.3):
2424
- Capacitor
@@ -223,7 +223,7 @@ SPEC CHECKSUMS:
223223
CapacitorBrowser: 2688852d02f1e89560a31b70521c71a5e7348860
224224
CapacitorCamera: 9b5c8e809c1042f263994f97ba846aa37e974f12
225225
CapacitorClipboard: 46f3959735fa0d96b9989dafcc4aed52e624d163
226-
CapacitorCommunityAdvertisingId: ffbeee30080f0057f7af6e465a7552b68a3d3fdf
226+
CapacitorCommunityAdvertisingId: 41543d8212fb12b6913b798bf1442c2a6bc1ae91
227227
CapacitorCommunityBluetoothLe: 7de4f21022a05b15195abfb002872884d00715fc
228228
CapacitorCommunityHttp: 7be90668527ef14ee10d08135b0e00fac9cf8247
229229
CapacitorCommunityWifi: 47188c74f2c6bcaefb619380863be8c67b1917c8

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@angular/router": "^14.2.0",
3232
"@awesome-cordova-plugins/core": "^5.46.0",
3333
"@awesome-cordova-plugins/in-app-purchase-2": "^5.43.0",
34-
"@capacitor-community/advertising-id": "^1.0.0",
34+
"@capacitor-community/advertising-id": "^5.0.0",
3535
"@capacitor-community/bluetooth-le": "^2.2.3",
3636
"@capacitor-community/http": "github:numbersprotocol/http#fix-catch-disabled-Local-Network-case-on-iOS",
3737
"@capacitor-community/wifi": "github:numbersprotocol/community-capacitor-wifi#capacitor3",
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Injectable } from '@angular/core';
22
import { AdvertisingId } from '@capacitor-community/advertising-id';
3+
import { Capacitor } from '@capacitor/core';
34
import { Platform } from '@ionic/angular';
4-
import { AFEvent, AFInit, AppsFlyer } from 'appsflyer-capacitor-plugin';
5+
import { AFInit, AppsFlyer } from 'appsflyer-capacitor-plugin';
56
import { APPS_FLYER_DEV_KEY } from '../dia-backend/secret';
67

78
@Injectable({
@@ -25,43 +26,33 @@ export class AppsFlyerService {
2526
constructor(private readonly platform: Platform) {}
2627

2728
async initAppsFlyerSDK() {
28-
await this.platform.ready();
29+
try {
30+
await this.platform.ready();
2931

30-
if (this.shouldInit === false) return;
32+
if (this.shouldInit === false) return;
3133

32-
if (this.platform.is('ios')) {
3334
await AdvertisingId.requestTracking();
34-
}
35-
36-
await AppsFlyer.initSDK(this.afConfig);
37-
}
3835

39-
private get shouldInit() {
40-
/**
41-
* Do not init apps flyer SDK if dev key is not provided.
42-
*/
43-
// eslint-disable-next-line no-extra-boolean-cast, @typescript-eslint/no-unnecessary-condition
44-
if (!!APPS_FLYER_DEV_KEY) {
45-
return false;
46-
}
47-
/**
48-
* Do not init apps flyer SDK in Web environment.
49-
*/
50-
if (!this.isNativePlatform) {
51-
return false;
36+
await AppsFlyer.initSDK(this.afConfig);
37+
} catch (error) {
38+
// TODO: Report error to Crashlytics or any other error reporting service if available.
5239
}
53-
return true;
5440
}
5541

56-
async trackUserOpenedWalletsPage() {
57-
if (this.isNativePlatform) return;
58-
59-
const data: AFEvent = { eventName: 'open-wallets-page' };
60-
61-
return AppsFlyer.logEvent(data).catch(() => ({}));
62-
}
63-
64-
private get isNativePlatform() {
65-
return this.platform.is('hybrid');
42+
/**
43+
* Determines whether AppsFlyer should be initialized.
44+
* In APK debug or QA builds, we pass an empty string ("") as the APPS_FLYER_DEV_KEY
45+
* to prevent AppsFlyer initialization. This approach helps avoid unnecessary analytics
46+
* or install counts in development (DEV) or quality assurance (QA) builds.
47+
* AppsFlyer will only be initialized if the following conditions are met:
48+
* 1. The APPS_FLYER_DEV_KEY is truthy (not an empty string).
49+
* 2. The app is running on a native platform (e.g., a mobile device).
50+
*
51+
* @returns {boolean} True if AppsFlyer should be initialized, otherwise false.
52+
*/
53+
// eslint-disable-next-line class-methods-use-this
54+
private get shouldInit() {
55+
const isTruthy = Boolean(APPS_FLYER_DEV_KEY);
56+
return isTruthy && Capacitor.isNativePlatform();
6657
}
6758
}

0 commit comments

Comments
 (0)