Skip to content

Commit 2dc3dbf

Browse files
committed
refactor(appsflyer): document, remove unused method
1 parent 35035c7 commit 2dc3dbf

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed
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)