@capawesome/capacitor-singular 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorSingular.podspec +19 -0
- package/LICENSE +21 -0
- package/Package.swift +26 -0
- package/README.md +1262 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/Singular.java +443 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/SingularHelper.java +53 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/SingularPlugin.java +336 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/CustomExceptions.java +34 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/DeviceAttributionInfoReceivedEvent.java +48 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/SdidReceivedEvent.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/SdidSetEvent.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/SingularLinkResolvedEvent.java +44 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/CreateReferrerShortLinkOptions.java +61 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/InitializeOptions.java +168 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetCustomUserIdOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetDeviceTokenOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetGlobalPropertyOptions.java +44 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetLimitAdvertisingIdentifiersOptions.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetLimitDataSharingOptions.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/TrackAdRevenueOptions.java +157 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/TrackEventOptions.java +35 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/TrackRevenueOptions.java +56 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/UnsetGlobalPropertyOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/CreateReferrerShortLinkResult.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/GetGlobalPropertiesResult.java +31 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/GetLimitDataSharingResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/IsAllTrackingStoppedResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +2014 -0
- package/dist/esm/definitions.d.ts +925 -0
- package/dist/esm/definitions.js +39 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.js +73 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +126 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +129 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Events/DeviceAttributionInfoReceivedEvent.swift +43 -0
- package/ios/Plugin/Classes/Events/SdidReceivedEvent.swift +16 -0
- package/ios/Plugin/Classes/Events/SdidSetEvent.swift +16 -0
- package/ios/Plugin/Classes/Events/SingularLinkResolvedEvent.swift +28 -0
- package/ios/Plugin/Classes/Events/SkanConversionValueUpdatedEvent.swift +30 -0
- package/ios/Plugin/Classes/Options/CreateReferrerShortLinkOptions.swift +25 -0
- package/ios/Plugin/Classes/Options/InitializeOptions.swift +44 -0
- package/ios/Plugin/Classes/Options/SetCustomUserIdOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetDeviceTokenOptions.swift +30 -0
- package/ios/Plugin/Classes/Options/SetGlobalPropertyOptions.swift +20 -0
- package/ios/Plugin/Classes/Options/SetLimitAdvertisingIdentifiersOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetLimitDataSharingOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SkanUpdateConversionValueOptions.swift +27 -0
- package/ios/Plugin/Classes/Options/TrackAdRevenueOptions.swift +47 -0
- package/ios/Plugin/Classes/Options/TrackEventOptions.swift +15 -0
- package/ios/Plugin/Classes/Options/TrackRevenueOptions.swift +22 -0
- package/ios/Plugin/Classes/Options/UnsetGlobalPropertyOptions.swift +13 -0
- package/ios/Plugin/Classes/Results/CreateReferrerShortLinkResult.swift +16 -0
- package/ios/Plugin/Classes/Results/GetGlobalPropertiesResult.swift +16 -0
- package/ios/Plugin/Classes/Results/GetLimitDataSharingResult.swift +16 -0
- package/ios/Plugin/Classes/Results/IsAllTrackingStoppedResult.swift +16 -0
- package/ios/Plugin/Classes/Results/SkanGetConversionValueResult.swift +20 -0
- package/ios/Plugin/Enums/CustomError.swift +88 -0
- package/ios/Plugin/Enums/SkanCoarseConversionValue.swift +31 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +6 -0
- package/ios/Plugin/Singular.swift +341 -0
- package/ios/Plugin/SingularHelper.swift +40 -0
- package/ios/Plugin/SingularPlugin.swift +340 -0
- package/package.json +102 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
singularSdkVersion = project.hasProperty('singularSdkVersion') ? rootProject.ext.singularSdkVersion : '12.16.0'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
buildscript {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
dependencies {
|
|
15
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apply plugin: 'com.android.library'
|
|
20
|
+
|
|
21
|
+
android {
|
|
22
|
+
namespace = "io.capawesome.capacitorjs.plugins.singular"
|
|
23
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
24
|
+
defaultConfig {
|
|
25
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
26
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
27
|
+
versionCode 1
|
|
28
|
+
versionName "1.0"
|
|
29
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
30
|
+
}
|
|
31
|
+
buildTypes {
|
|
32
|
+
release {
|
|
33
|
+
minifyEnabled false
|
|
34
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
lintOptions {
|
|
38
|
+
abortOnError = false
|
|
39
|
+
}
|
|
40
|
+
compileOptions {
|
|
41
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
42
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
repositories {
|
|
47
|
+
google()
|
|
48
|
+
mavenCentral()
|
|
49
|
+
maven { url 'https://maven.singular.net/' }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
dependencies {
|
|
54
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
55
|
+
implementation project(':capacitor-android')
|
|
56
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
57
|
+
implementation "com.singular.sdk:singular_sdk:$singularSdkVersion"
|
|
58
|
+
testImplementation "junit:junit:$junitVersion"
|
|
59
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
60
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
61
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
3
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
4
|
+
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
|
|
5
|
+
</manifest>
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.singular;
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.annotation.Nullable;
|
|
7
|
+
import com.getcapacitor.JSObject;
|
|
8
|
+
import com.singular.sdk.SDIDAccessorHandler;
|
|
9
|
+
import com.singular.sdk.ShortLinkHandler;
|
|
10
|
+
import com.singular.sdk.SingularAdData;
|
|
11
|
+
import com.singular.sdk.SingularConfig;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.CustomExceptions;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.events.DeviceAttributionInfoReceivedEvent;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.events.SdidReceivedEvent;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.events.SdidSetEvent;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.events.SingularLinkResolvedEvent;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.CreateReferrerShortLinkOptions;
|
|
18
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.InitializeOptions;
|
|
19
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.SetCustomUserIdOptions;
|
|
20
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.SetDeviceTokenOptions;
|
|
21
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.SetGlobalPropertyOptions;
|
|
22
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.SetLimitAdvertisingIdentifiersOptions;
|
|
23
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.SetLimitDataSharingOptions;
|
|
24
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.TrackAdRevenueOptions;
|
|
25
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.TrackEventOptions;
|
|
26
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.TrackRevenueOptions;
|
|
27
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.options.UnsetGlobalPropertyOptions;
|
|
28
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.results.CreateReferrerShortLinkResult;
|
|
29
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.results.GetGlobalPropertiesResult;
|
|
30
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.results.GetLimitDataSharingResult;
|
|
31
|
+
import io.capawesome.capacitorjs.plugins.singular.classes.results.IsAllTrackingStoppedResult;
|
|
32
|
+
import io.capawesome.capacitorjs.plugins.singular.interfaces.EmptyCallback;
|
|
33
|
+
import io.capawesome.capacitorjs.plugins.singular.interfaces.NonEmptyResultCallback;
|
|
34
|
+
import java.util.List;
|
|
35
|
+
import java.util.Map;
|
|
36
|
+
|
|
37
|
+
public class Singular {
|
|
38
|
+
|
|
39
|
+
@NonNull
|
|
40
|
+
private final SingularPlugin plugin;
|
|
41
|
+
|
|
42
|
+
@Nullable
|
|
43
|
+
private InitializeOptions initializeOptions;
|
|
44
|
+
|
|
45
|
+
private boolean initialized = false;
|
|
46
|
+
|
|
47
|
+
public Singular(@NonNull SingularPlugin plugin) {
|
|
48
|
+
this.plugin = plugin;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public void clearGlobalProperties(@NonNull EmptyCallback callback) {
|
|
52
|
+
try {
|
|
53
|
+
requireInitialized();
|
|
54
|
+
com.singular.sdk.Singular.clearGlobalProperties();
|
|
55
|
+
callback.success();
|
|
56
|
+
} catch (Exception exception) {
|
|
57
|
+
callback.error(exception);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public void createReferrerShortLink(
|
|
62
|
+
@NonNull CreateReferrerShortLinkOptions options,
|
|
63
|
+
@NonNull NonEmptyResultCallback<CreateReferrerShortLinkResult> callback
|
|
64
|
+
) {
|
|
65
|
+
try {
|
|
66
|
+
requireInitialized();
|
|
67
|
+
com.singular.sdk.Singular.createReferrerShortLink(
|
|
68
|
+
options.getBaseLink(),
|
|
69
|
+
options.getReferrerName(),
|
|
70
|
+
options.getReferrerId(),
|
|
71
|
+
options.getPassthroughParameters(),
|
|
72
|
+
new ShortLinkHandler() {
|
|
73
|
+
@Override
|
|
74
|
+
public void onSuccess(String link) {
|
|
75
|
+
callback.success(new CreateReferrerShortLinkResult(link));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Override
|
|
79
|
+
public void onError(String error) {
|
|
80
|
+
callback.error(new Exception(error));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
} catch (Exception exception) {
|
|
85
|
+
callback.error(exception);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public void getGlobalProperties(@NonNull NonEmptyResultCallback<GetGlobalPropertiesResult> callback) {
|
|
90
|
+
try {
|
|
91
|
+
requireInitialized();
|
|
92
|
+
Map<String, String> properties = com.singular.sdk.Singular.getGlobalProperties();
|
|
93
|
+
callback.success(new GetGlobalPropertiesResult(properties));
|
|
94
|
+
} catch (Exception exception) {
|
|
95
|
+
callback.error(exception);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public void getLimitDataSharing(@NonNull NonEmptyResultCallback<GetLimitDataSharingResult> callback) {
|
|
100
|
+
try {
|
|
101
|
+
requireInitialized();
|
|
102
|
+
boolean limit = com.singular.sdk.Singular.getLimitDataSharing();
|
|
103
|
+
callback.success(new GetLimitDataSharingResult(limit));
|
|
104
|
+
} catch (Exception exception) {
|
|
105
|
+
callback.error(exception);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public void handleNewIntent(@NonNull Intent intent) {
|
|
110
|
+
InitializeOptions options = initializeOptions;
|
|
111
|
+
if (!initialized || options == null) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Initializing the SDK again with the new intent delivers the Singular Link of a warm start.
|
|
115
|
+
com.singular.sdk.Singular.init(plugin.getContext().getApplicationContext(), createConfig(options, intent));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public void initialize(@NonNull InitializeOptions options, @NonNull EmptyCallback callback) {
|
|
119
|
+
try {
|
|
120
|
+
initializeOptions = options;
|
|
121
|
+
SingularConfig config = createConfig(options, plugin.getActivity().getIntent());
|
|
122
|
+
boolean success = com.singular.sdk.Singular.init(plugin.getContext().getApplicationContext(), config);
|
|
123
|
+
if (!success) {
|
|
124
|
+
throw CustomExceptions.INITIALIZATION_FAILED;
|
|
125
|
+
}
|
|
126
|
+
initialized = true;
|
|
127
|
+
callback.success();
|
|
128
|
+
} catch (Exception exception) {
|
|
129
|
+
callback.error(exception);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public void isAllTrackingStopped(@NonNull NonEmptyResultCallback<IsAllTrackingStoppedResult> callback) {
|
|
134
|
+
try {
|
|
135
|
+
requireInitialized();
|
|
136
|
+
boolean stopped = com.singular.sdk.Singular.isAllTrackingStopped();
|
|
137
|
+
callback.success(new IsAllTrackingStoppedResult(stopped));
|
|
138
|
+
} catch (Exception exception) {
|
|
139
|
+
callback.error(exception);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public void resumeAllTracking(@NonNull EmptyCallback callback) {
|
|
144
|
+
try {
|
|
145
|
+
requireInitialized();
|
|
146
|
+
com.singular.sdk.Singular.resumeAllTracking();
|
|
147
|
+
callback.success();
|
|
148
|
+
} catch (Exception exception) {
|
|
149
|
+
callback.error(exception);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public void setCustomUserId(@NonNull SetCustomUserIdOptions options, @NonNull EmptyCallback callback) {
|
|
154
|
+
try {
|
|
155
|
+
requireInitialized();
|
|
156
|
+
com.singular.sdk.Singular.setCustomUserId(options.getCustomUserId());
|
|
157
|
+
callback.success();
|
|
158
|
+
} catch (Exception exception) {
|
|
159
|
+
callback.error(exception);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public void setDeviceToken(@NonNull SetDeviceTokenOptions options, @NonNull EmptyCallback callback) {
|
|
164
|
+
try {
|
|
165
|
+
requireInitialized();
|
|
166
|
+
com.singular.sdk.Singular.setFCMDeviceToken(options.getToken());
|
|
167
|
+
callback.success();
|
|
168
|
+
} catch (Exception exception) {
|
|
169
|
+
callback.error(exception);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public void setGlobalProperty(@NonNull SetGlobalPropertyOptions options, @NonNull EmptyCallback callback) {
|
|
174
|
+
try {
|
|
175
|
+
requireInitialized();
|
|
176
|
+
boolean success = com.singular.sdk.Singular.setGlobalProperty(
|
|
177
|
+
options.getKey(),
|
|
178
|
+
options.getValue(),
|
|
179
|
+
options.isOverrideExisting()
|
|
180
|
+
);
|
|
181
|
+
if (!success) {
|
|
182
|
+
throw CustomExceptions.GLOBAL_PROPERTY_COULD_NOT_BE_SET;
|
|
183
|
+
}
|
|
184
|
+
callback.success();
|
|
185
|
+
} catch (Exception exception) {
|
|
186
|
+
callback.error(exception);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public void setLimitAdvertisingIdentifiers(@NonNull SetLimitAdvertisingIdentifiersOptions options, @NonNull EmptyCallback callback) {
|
|
191
|
+
try {
|
|
192
|
+
requireInitialized();
|
|
193
|
+
com.singular.sdk.Singular.setLimitAdvertisingIdentifiers(options.isLimit());
|
|
194
|
+
callback.success();
|
|
195
|
+
} catch (Exception exception) {
|
|
196
|
+
callback.error(exception);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public void setLimitDataSharing(@NonNull SetLimitDataSharingOptions options, @NonNull EmptyCallback callback) {
|
|
201
|
+
try {
|
|
202
|
+
requireInitialized();
|
|
203
|
+
com.singular.sdk.Singular.limitDataSharing(options.isLimit());
|
|
204
|
+
callback.success();
|
|
205
|
+
} catch (Exception exception) {
|
|
206
|
+
callback.error(exception);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public void stopAllTracking(@NonNull EmptyCallback callback) {
|
|
211
|
+
try {
|
|
212
|
+
requireInitialized();
|
|
213
|
+
com.singular.sdk.Singular.stopAllTracking();
|
|
214
|
+
callback.success();
|
|
215
|
+
} catch (Exception exception) {
|
|
216
|
+
callback.error(exception);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public void trackAdRevenue(@NonNull TrackAdRevenueOptions options, @NonNull EmptyCallback callback) {
|
|
221
|
+
try {
|
|
222
|
+
requireInitialized();
|
|
223
|
+
com.singular.sdk.Singular.adRevenue(createAdData(options));
|
|
224
|
+
callback.success();
|
|
225
|
+
} catch (Exception exception) {
|
|
226
|
+
callback.error(exception);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public void trackEvent(@NonNull TrackEventOptions options, @NonNull EmptyCallback callback) {
|
|
231
|
+
try {
|
|
232
|
+
requireInitialized();
|
|
233
|
+
JSObject attributes = options.getAttributes();
|
|
234
|
+
boolean success =
|
|
235
|
+
attributes == null
|
|
236
|
+
? com.singular.sdk.Singular.event(options.getName())
|
|
237
|
+
: com.singular.sdk.Singular.eventJSON(options.getName(), attributes);
|
|
238
|
+
if (!success) {
|
|
239
|
+
throw CustomExceptions.EVENT_COULD_NOT_BE_TRACKED;
|
|
240
|
+
}
|
|
241
|
+
callback.success();
|
|
242
|
+
} catch (Exception exception) {
|
|
243
|
+
callback.error(exception);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public void trackRevenue(@NonNull TrackRevenueOptions options, @NonNull EmptyCallback callback) {
|
|
248
|
+
try {
|
|
249
|
+
requireInitialized();
|
|
250
|
+
String currency = options.getCurrency();
|
|
251
|
+
double amount = options.getAmount();
|
|
252
|
+
Map<String, Object> attributes = options.getAttributes();
|
|
253
|
+
String eventName = options.getEventName();
|
|
254
|
+
boolean success;
|
|
255
|
+
if (eventName == null) {
|
|
256
|
+
success =
|
|
257
|
+
attributes == null
|
|
258
|
+
? com.singular.sdk.Singular.revenue(currency, amount)
|
|
259
|
+
: com.singular.sdk.Singular.revenue(currency, amount, attributes);
|
|
260
|
+
} else {
|
|
261
|
+
success =
|
|
262
|
+
attributes == null
|
|
263
|
+
? com.singular.sdk.Singular.customRevenue(eventName, currency, amount)
|
|
264
|
+
: com.singular.sdk.Singular.customRevenue(eventName, currency, amount, attributes);
|
|
265
|
+
}
|
|
266
|
+
if (!success) {
|
|
267
|
+
throw CustomExceptions.REVENUE_COULD_NOT_BE_TRACKED;
|
|
268
|
+
}
|
|
269
|
+
callback.success();
|
|
270
|
+
} catch (Exception exception) {
|
|
271
|
+
callback.error(exception);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
public void trackingOptIn(@NonNull EmptyCallback callback) {
|
|
276
|
+
try {
|
|
277
|
+
requireInitialized();
|
|
278
|
+
com.singular.sdk.Singular.trackingOptIn();
|
|
279
|
+
callback.success();
|
|
280
|
+
} catch (Exception exception) {
|
|
281
|
+
callback.error(exception);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public void trackingUnder13(@NonNull EmptyCallback callback) {
|
|
286
|
+
try {
|
|
287
|
+
requireInitialized();
|
|
288
|
+
com.singular.sdk.Singular.trackingUnder13();
|
|
289
|
+
callback.success();
|
|
290
|
+
} catch (Exception exception) {
|
|
291
|
+
callback.error(exception);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public void unsetCustomUserId(@NonNull EmptyCallback callback) {
|
|
296
|
+
try {
|
|
297
|
+
requireInitialized();
|
|
298
|
+
com.singular.sdk.Singular.unsetCustomUserId();
|
|
299
|
+
callback.success();
|
|
300
|
+
} catch (Exception exception) {
|
|
301
|
+
callback.error(exception);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
public void unsetGlobalProperty(@NonNull UnsetGlobalPropertyOptions options, @NonNull EmptyCallback callback) {
|
|
306
|
+
try {
|
|
307
|
+
requireInitialized();
|
|
308
|
+
com.singular.sdk.Singular.unsetGlobalProperty(options.getKey());
|
|
309
|
+
callback.success();
|
|
310
|
+
} catch (Exception exception) {
|
|
311
|
+
callback.error(exception);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
@NonNull
|
|
316
|
+
private SingularAdData createAdData(@NonNull TrackAdRevenueOptions options) {
|
|
317
|
+
SingularAdData adData = new SingularAdData(options.getAdPlatform(), options.getCurrency(), options.getRevenue());
|
|
318
|
+
String adGroupId = options.getAdGroupId();
|
|
319
|
+
if (adGroupId != null) {
|
|
320
|
+
adData.withAdGroupId(adGroupId);
|
|
321
|
+
}
|
|
322
|
+
String adGroupName = options.getAdGroupName();
|
|
323
|
+
if (adGroupName != null) {
|
|
324
|
+
adData.withAdGroupName(adGroupName);
|
|
325
|
+
}
|
|
326
|
+
String adGroupPriority = options.getAdGroupPriority();
|
|
327
|
+
if (adGroupPriority != null) {
|
|
328
|
+
adData.withAdGroupPriority(adGroupPriority);
|
|
329
|
+
}
|
|
330
|
+
String adGroupType = options.getAdGroupType();
|
|
331
|
+
if (adGroupType != null) {
|
|
332
|
+
adData.withAdGroupType(adGroupType);
|
|
333
|
+
}
|
|
334
|
+
String adPlacementName = options.getAdPlacementName();
|
|
335
|
+
if (adPlacementName != null) {
|
|
336
|
+
adData.withAdPlacementName(adPlacementName);
|
|
337
|
+
}
|
|
338
|
+
String adType = options.getAdType();
|
|
339
|
+
if (adType != null) {
|
|
340
|
+
adData.withAdType(adType);
|
|
341
|
+
}
|
|
342
|
+
String adUnitId = options.getAdUnitId();
|
|
343
|
+
if (adUnitId != null) {
|
|
344
|
+
adData.withAdUnitId(adUnitId);
|
|
345
|
+
}
|
|
346
|
+
String adUnitName = options.getAdUnitName();
|
|
347
|
+
if (adUnitName != null) {
|
|
348
|
+
adData.withAdUnitName(adUnitName);
|
|
349
|
+
}
|
|
350
|
+
String impressionId = options.getImpressionId();
|
|
351
|
+
if (impressionId != null) {
|
|
352
|
+
adData.withImpressionId(impressionId);
|
|
353
|
+
}
|
|
354
|
+
String networkName = options.getNetworkName();
|
|
355
|
+
if (networkName != null) {
|
|
356
|
+
adData.withNetworkName(networkName);
|
|
357
|
+
}
|
|
358
|
+
String placementId = options.getPlacementId();
|
|
359
|
+
if (placementId != null) {
|
|
360
|
+
adData.withPlacementId(placementId);
|
|
361
|
+
}
|
|
362
|
+
String precision = options.getPrecision();
|
|
363
|
+
if (precision != null) {
|
|
364
|
+
adData.withPrecision(precision);
|
|
365
|
+
}
|
|
366
|
+
return adData;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
@NonNull
|
|
370
|
+
private SingularConfig createConfig(@NonNull InitializeOptions options, @NonNull Intent intent) {
|
|
371
|
+
SingularConfig config = new SingularConfig(options.getApiKey(), options.getSecret());
|
|
372
|
+
config.withSessionTimeoutInSec(options.getSessionTimeout());
|
|
373
|
+
config.withSingularLink(
|
|
374
|
+
intent,
|
|
375
|
+
linkParams -> plugin.notifySingularLinkResolvedListeners(new SingularLinkResolvedEvent(linkParams)),
|
|
376
|
+
options.getShortLinkResolveTimeout()
|
|
377
|
+
);
|
|
378
|
+
config.withSingularDeviceAttribution(attributionInfo ->
|
|
379
|
+
plugin.notifyDeviceAttributionInfoReceivedListeners(new DeviceAttributionInfoReceivedEvent(attributionInfo))
|
|
380
|
+
);
|
|
381
|
+
String androidFacebookAppId = options.getAndroidFacebookAppId();
|
|
382
|
+
if (androidFacebookAppId != null) {
|
|
383
|
+
config.withFacebookAppId(androidFacebookAppId);
|
|
384
|
+
}
|
|
385
|
+
List<String> brandedDomains = options.getBrandedDomains();
|
|
386
|
+
if (brandedDomains != null) {
|
|
387
|
+
config.withBrandedDomains(brandedDomains);
|
|
388
|
+
}
|
|
389
|
+
SDIDAccessorHandler sdidAccessorHandler = createSdidAccessorHandler();
|
|
390
|
+
String customSdid = options.getCustomSdid();
|
|
391
|
+
if (customSdid == null) {
|
|
392
|
+
config.withSdidAccessorHandler(sdidAccessorHandler);
|
|
393
|
+
} else {
|
|
394
|
+
config.withCustomSdid(customSdid, sdidAccessorHandler);
|
|
395
|
+
}
|
|
396
|
+
String customUserId = options.getCustomUserId();
|
|
397
|
+
if (customUserId != null) {
|
|
398
|
+
config.withCustomUserId(customUserId);
|
|
399
|
+
}
|
|
400
|
+
List<String> espDomains = options.getEspDomains();
|
|
401
|
+
if (espDomains != null) {
|
|
402
|
+
config.withESPDomains(espDomains);
|
|
403
|
+
}
|
|
404
|
+
Map<String, String> globalProperties = options.getGlobalProperties();
|
|
405
|
+
if (globalProperties != null) {
|
|
406
|
+
for (Map.Entry<String, String> property : globalProperties.entrySet()) {
|
|
407
|
+
config.withGlobalProperty(property.getKey(), property.getValue(), true);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (options.isLimitAdvertisingIdentifiers()) {
|
|
411
|
+
config.withLimitAdvertisingIdentifiers();
|
|
412
|
+
}
|
|
413
|
+
Boolean limitDataSharing = options.getLimitDataSharing();
|
|
414
|
+
if (limitDataSharing != null) {
|
|
415
|
+
config.withLimitDataSharing(limitDataSharing);
|
|
416
|
+
}
|
|
417
|
+
if (options.isLoggingEnabled()) {
|
|
418
|
+
config.withLoggingEnabled().withLogLevel(Log.DEBUG);
|
|
419
|
+
}
|
|
420
|
+
return config;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
@NonNull
|
|
424
|
+
private SDIDAccessorHandler createSdidAccessorHandler() {
|
|
425
|
+
return new SDIDAccessorHandler() {
|
|
426
|
+
@Override
|
|
427
|
+
public void didSetSdid(String sdid) {
|
|
428
|
+
plugin.notifySdidSetListeners(new SdidSetEvent(sdid));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
@Override
|
|
432
|
+
public void sdidReceived(String sdid) {
|
|
433
|
+
plugin.notifySdidReceivedListeners(new SdidReceivedEvent(sdid));
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private void requireInitialized() throws Exception {
|
|
439
|
+
if (!initialized) {
|
|
440
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.singular;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
import java.util.ArrayList;
|
|
5
|
+
import java.util.HashMap;
|
|
6
|
+
import java.util.Iterator;
|
|
7
|
+
import org.json.JSONArray;
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
public class SingularHelper {
|
|
12
|
+
|
|
13
|
+
@Nullable
|
|
14
|
+
public static HashMap<String, Object> createHashMapFromJSONObject(@Nullable JSONObject object) throws JSONException {
|
|
15
|
+
if (object == null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
HashMap<String, Object> map = new HashMap<>();
|
|
19
|
+
Iterator<String> keys = object.keys();
|
|
20
|
+
while (keys.hasNext()) {
|
|
21
|
+
String key = keys.next();
|
|
22
|
+
Object value = createObjectFromJSValue(object.get(key));
|
|
23
|
+
map.put(key, value);
|
|
24
|
+
}
|
|
25
|
+
return map;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static Object createObjectFromJSValue(Object value) throws JSONException {
|
|
29
|
+
if (value == JSONObject.NULL) {
|
|
30
|
+
return null;
|
|
31
|
+
} else if (value instanceof JSONObject) {
|
|
32
|
+
return createHashMapFromJSONObject((JSONObject) value);
|
|
33
|
+
} else if (value instanceof JSONArray) {
|
|
34
|
+
return createArrayListFromJSONArray((JSONArray) value);
|
|
35
|
+
} else {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private static ArrayList<Object> createArrayListFromJSONArray(JSONArray array) throws JSONException {
|
|
41
|
+
ArrayList<Object> arrayList = new ArrayList<>();
|
|
42
|
+
for (int x = 0; x < array.length(); x++) {
|
|
43
|
+
Object value = array.get(x);
|
|
44
|
+
if (value instanceof JSONObject) {
|
|
45
|
+
value = createHashMapFromJSONObject((JSONObject) value);
|
|
46
|
+
} else if (value instanceof JSONArray) {
|
|
47
|
+
value = createArrayListFromJSONArray((JSONArray) value);
|
|
48
|
+
}
|
|
49
|
+
arrayList.add(value);
|
|
50
|
+
}
|
|
51
|
+
return arrayList;
|
|
52
|
+
}
|
|
53
|
+
}
|