-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmain.dart
429 lines (389 loc) · 15.8 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import 'package:adjust_sdk/adjust.dart';
import 'package:adjust_sdk/adjust_attribution.dart';
import 'package:adjust_sdk/adjust_config.dart';
import 'package:adjust_sdk/adjust_event_failure.dart';
import 'package:adjust_sdk/adjust_event_success.dart';
import 'package:adjust_sdk/adjust_session_failure.dart';
import 'package:adjust_sdk/adjust_session_success.dart';
import 'package:adjust_sdk/adjust_extensions.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'util.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String? title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
bool _isSdkEnabled = true;
@override
initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);
initPlatformState();
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.inactive:
break;
case AppLifecycleState.resumed:
break;
case AppLifecycleState.paused:
break;
case AppLifecycleState.detached:
break;
}
}
// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
AdjustConfig config =
AdjustConfigBuilder.create('2fm9gkqubvpc', AdjustEnvironment.sandbox)
.setLogLevel(AdjustLogLevel.verbose)
.withUrlStrategy([
'adjust.net.in',
'adjust.com'
], true, false).setAttributionCallback(
(AdjustAttribution attributionChangedData) {
print('[Adjust]: Attribution changed!');
if (attributionChangedData.trackerToken != null) {
print(
'[Adjust]: Tracker token: ' + attributionChangedData.trackerToken!);
}
if (attributionChangedData.trackerName != null) {
print('[Adjust]: Tracker name: ' + attributionChangedData.trackerName!);
}
if (attributionChangedData.campaign != null) {
print('[Adjust]: Campaign: ' + attributionChangedData.campaign!);
}
if (attributionChangedData.network != null) {
print('[Adjust]: Network: ' + attributionChangedData.network!);
}
if (attributionChangedData.creative != null) {
print('[Adjust]: Creative: ' + attributionChangedData.creative!);
}
if (attributionChangedData.adgroup != null) {
print('[Adjust]: Adgroup: ' + attributionChangedData.adgroup!);
}
if (attributionChangedData.clickLabel != null) {
print('[Adjust]: Click label: ' + attributionChangedData.clickLabel!);
}
if (attributionChangedData.costType != null) {
print('[Adjust]: Cost type: ' + attributionChangedData.costType!);
}
if (attributionChangedData.costAmount != null) {
print('[Adjust]: Cost amount: ' +
attributionChangedData.costAmount!.toString());
}
if (attributionChangedData.costCurrency != null) {
print(
'[Adjust]: Cost currency: ' + attributionChangedData.costCurrency!);
}
}).setSessionSuccessCallback((AdjustSessionSuccess sessionSuccessData) {
print('[Adjust]: Session tracking success!');
if (sessionSuccessData.message != null) {
print('[Adjust]: Message: ' + sessionSuccessData.message!);
}
if (sessionSuccessData.timestamp != null) {
print('[Adjust]: Timestamp: ' + sessionSuccessData.timestamp!);
}
if (sessionSuccessData.adid != null) {
print('[Adjust]: Adid: ' + sessionSuccessData.adid!);
}
if (sessionSuccessData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + sessionSuccessData.jsonResponse!);
}
}).setSessionFailureCallback((AdjustSessionFailure sessionFailureData) {
print('[Adjust]: Session tracking failure!');
if (sessionFailureData.message != null) {
print('[Adjust]: Message: ' + sessionFailureData.message!);
}
if (sessionFailureData.timestamp != null) {
print('[Adjust]: Timestamp: ' + sessionFailureData.timestamp!);
}
if (sessionFailureData.adid != null) {
print('[Adjust]: Adid: ' + sessionFailureData.adid!);
}
if (sessionFailureData.willRetry != null) {
print(
'[Adjust]: Will retry: ' + sessionFailureData.willRetry.toString());
}
if (sessionFailureData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + sessionFailureData.jsonResponse!);
}
}).setEventSuccessCallback((AdjustEventSuccess eventSuccessData) {
print('[Adjust]: Event tracking success!');
if (eventSuccessData.eventToken != null) {
print('[Adjust]: Event token: ' + eventSuccessData.eventToken!);
}
if (eventSuccessData.message != null) {
print('[Adjust]: Message: ' + eventSuccessData.message!);
}
if (eventSuccessData.timestamp != null) {
print('[Adjust]: Timestamp: ' + eventSuccessData.timestamp!);
}
if (eventSuccessData.adid != null) {
print('[Adjust]: Adid: ' + eventSuccessData.adid!);
}
if (eventSuccessData.callbackId != null) {
print('[Adjust]: Callback ID: ' + eventSuccessData.callbackId!);
}
if (eventSuccessData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + eventSuccessData.jsonResponse!);
}
}).setEventFailureCallback((AdjustEventFailure eventFailureData) {
print('[Adjust]: Event tracking failure!');
if (eventFailureData.eventToken != null) {
print('[Adjust]: Event token: ' + eventFailureData.eventToken!);
}
if (eventFailureData.message != null) {
print('[Adjust]: Message: ' + eventFailureData.message!);
}
if (eventFailureData.timestamp != null) {
print('[Adjust]: Timestamp: ' + eventFailureData.timestamp!);
}
if (eventFailureData.adid != null) {
print('[Adjust]: Adid: ' + eventFailureData.adid!);
}
if (eventFailureData.callbackId != null) {
print('[Adjust]: Callback ID: ' + eventFailureData.callbackId!);
}
if (eventFailureData.willRetry != null) {
print('[Adjust]: Will retry: ' + eventFailureData.willRetry.toString());
}
if (eventFailureData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + eventFailureData.jsonResponse!);
}
}).setDeferredDeeplinkCallback((String? uri) {
print('[Adjust]: Received deferred deeplink: ' + uri!);
}).setSkanUpdatedCallback((Map<String, String> skanUpdateData) {
print('[Adjust]: Received SKAN update information!');
if (skanUpdateData["conversion_value"] != null) {
print('[Adjust]: Conversion value: ' +
skanUpdateData["conversion_value"]!);
}
if (skanUpdateData["coarse_value"] != null) {
print('[Adjust]: Coarse value: ' + skanUpdateData["coarse_value"]!);
}
if (skanUpdateData["lock_window"] != null) {
print('[Adjust]: Lock window: ' + skanUpdateData["lock_window"]!);
}
if (skanUpdateData["error"] != null) {
print('[Adjust]: Error: ' + skanUpdateData["error"]!);
}
});
// Add session callback parameters.
Adjust.addGlobalCallbackParameter('scp_foo_1', 'scp_bar');
Adjust.addGlobalCallbackParameter('scp_foo_2', 'scp_value');
// Add session Partner parameters.
Adjust.addGlobalPartnerParameter('spp_foo_1', 'spp_bar');
Adjust.addGlobalPartnerParameter('spp_foo_2', 'spp_value');
// Remove session callback parameters.
Adjust.removeGlobalCallbackParameter('scp_foo_1');
Adjust.removeGlobalPartnerParameter('spp_foo_1');
// Clear all session callback parameters.
Adjust.removeGlobalCallbackParameters();
// Clear all session partner parameters.
Adjust.removeGlobalPartnerParameters();
// Ask for tracking consent.
Adjust.requestAppTrackingAuthorization().then((status) {
print('[Adjust]: Authorization status update!');
switch (status) {
case 0:
print(
'[Adjust]: Authorization status update: ATTrackingManagerAuthorizationStatusNotDetermined');
break;
case 1:
print(
'[Adjust]: Authorization status update: ATTrackingManagerAuthorizationStatusRestricted');
break;
case 2:
print(
'[Adjust]: Authorization status update: ATTrackingManagerAuthorizationStatusDenied');
break;
case 3:
print(
'[Adjust]: Authorization status update: ATTrackingManagerAuthorizationStatusAuthorized');
break;
}
});
// start SDK
Adjust.initSdk(config);
}
@override
Widget build(BuildContext context) {
return new CustomScrollView(
shrinkWrap: true,
slivers: <Widget>[
new SliverPadding(
padding: const EdgeInsets.all(20.0),
sliver: new SliverList(
delegate: new SliverChildListDelegate(
<Widget>[
const Padding(padding: const EdgeInsets.all(7.0)),
Util.buildCupertinoButton(
'Is Enabled ?', () => _showIsSdkEnabled()),
const Padding(padding: const EdgeInsets.all(7.0)),
// Track simple event button.
Util.buildCupertinoButton('Track Simple Event',
() => Adjust.trackEvent(Util.buildSimpleEvent())),
const Padding(padding: const EdgeInsets.all(7.0)),
// Track revenue event button.
Util.buildCupertinoButton('Track Revenue Event',
() => Adjust.trackEvent(Util.buildRevenueEvent())),
const Padding(padding: const EdgeInsets.all(7.0)),
// Track callback event button.
Util.buildCupertinoButton('Track Callback Event',
() => Adjust.trackEvent(Util.buildCallbackEvent())),
const Padding(padding: const EdgeInsets.all(7.0)),
// Track partner event button.
Util.buildCupertinoButton('Track Partner Event',
() => Adjust.trackEvent(Util.buildPartnerEvent())),
const Padding(padding: const EdgeInsets.all(7.0)),
// Get Google Advertising Id.
Util.buildCupertinoButton(
'Get Google AdId',
() => Adjust.getGoogleAdId().then((googleAdid) {
_showDialogMessage('Get Google Advertising Id',
'Received Google Advertising Id: $googleAdid');
})),
const Padding(padding: const EdgeInsets.all(7.0)),
// Get Adjust identifier.
Util.buildCupertinoButton(
'Get Adjust identifier',
() => Adjust.getAdid().then((adid) {
_showDialogMessage('Adjust identifier',
'Received Adjust identifier: $adid');
})),
const Padding(padding: const EdgeInsets.all(7.0)),
// Get IDFA.
Util.buildCupertinoButton(
'Get IDFA',
() => Adjust.getIdfa().then((idfa) {
_showDialogMessage('IDFA', 'Received IDFA: $idfa');
})),
const Padding(padding: const EdgeInsets.all(7.0)),
// Get attribution.
Util.buildCupertinoButton(
'Get attribution',
() => Adjust.getAttribution().then((attribution) {
_showDialogMessage('Attribution',
'Received attribution: ${attribution.toString()}');
})),
const Padding(padding: const EdgeInsets.all(7.0)),
// Enable / disable SDK.
new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
// Is SDK enabled switch.
new Text(
_isSdkEnabled ? 'Enabled' : 'Disabled',
style: _isSdkEnabled
? new TextStyle(fontSize: 32.0, color: Colors.green)
: new TextStyle(fontSize: 32.0, color: Colors.red),
),
new CupertinoSwitch(
value: _isSdkEnabled,
onChanged: (bool value) {
setState(() {
if (value == true) {
Adjust.enable();
} else {
Adjust.disable();
}
_isSdkEnabled = value;
print('Switch state = $_isSdkEnabled');
});
},
),
],
),
const Padding(padding: const EdgeInsets.all(7.0)),
// end
],
),
),
),
],
);
}
_showIsSdkEnabled() {
try {
Adjust.isEnabled().then((isEnabled) {
_isSdkEnabled = isEnabled;
_showDialogMessage('SDK Enabled?', 'Adjust is enabled = $isEnabled');
});
} on PlatformException {
_showDialogMessage(
'SDK Enabled?', 'No such method found in plugin: isEnabled');
}
}
void _showDialogMessage(String title, String text,
[bool printToConsoleAlso = true]) {
if (printToConsoleAlso) {
print(text);
}
showDialog<void>(
context: context,
builder: (BuildContext context) {
return new CupertinoAlertDialog(
title: Text(title),
content: Text(text),
actions: <Widget>[
new CupertinoDialogAction(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context, 'OK');
},
)
],
);
},
);
}
}