6
6
7
7
import org .apache .cordova .CallbackContext ;
8
8
import org .apache .cordova .CordovaPlugin ;
9
+ import org .apache .cordova .PluginResult ;
9
10
import org .json .JSONArray ;
10
11
import org .json .JSONException ;
11
12
import org .json .JSONObject ;
17
18
import android .telephony .TelephonyManager ;
18
19
19
20
import com .mobileapptracker .MATEventItem ;
21
+ import com .mobileapptracker .MATResponse ;
20
22
import com .mobileapptracker .MobileAppTracker ;
21
23
22
24
public class MATPlugin extends CordovaPlugin {
@@ -30,6 +32,7 @@ public class MATPlugin extends CordovaPlugin {
30
32
public static final String SETAPPADTRACKING = "setAppAdTracking" ;
31
33
public static final String SETALLOWDUP = "setAllowDuplicates" ;
32
34
public static final String SETDEBUG = "setDebugMode" ;
35
+ public static final String SETDELEGATE = "setDelegate" ;
33
36
public static final String SETDEVICEID = "setDeviceId" ;
34
37
public static final String SETEVENTATTRIBUTE1 = "setEventAttribute1" ;
35
38
public static final String SETEVENTATTRIBUTE2 = "setEventAttribute2" ;
@@ -502,6 +505,32 @@ public void run() {
502
505
boolean payingUser = tracker .getIsPayingUser ();
503
506
callbackContext .success (String .valueOf (payingUser ));
504
507
return true ;
508
+ } else if (SETDELEGATE .equals (action )) {
509
+ // default to true
510
+ boolean enabled = args .optBoolean (0 , true );
511
+ tracker .setMATResponse (new MATResponse () {
512
+ @ Override
513
+ public void enqueuedActionWithRefId (String refId ) {
514
+ PluginResult result = new PluginResult (PluginResult .Status .OK , "MATPlugin.matDelegate.enqueued: " + refId );
515
+ result .setKeepCallback (true );
516
+ callbackContext .sendPluginResult (result );
517
+ }
518
+
519
+ @ Override
520
+ public void didSucceedWithData (JSONObject data ) {
521
+ PluginResult result = new PluginResult (PluginResult .Status .OK , data .toString ());
522
+ result .setKeepCallback (true );
523
+ callbackContext .sendPluginResult (result );
524
+ }
525
+
526
+ @ Override
527
+ public void didFailWithError (JSONObject error ) {
528
+ PluginResult result = new PluginResult (PluginResult .Status .OK , error .toString ());
529
+ result .setKeepCallback (true );
530
+ callbackContext .sendPluginResult (result );
531
+ }
532
+ });
533
+ return true ;
505
534
} else {
506
535
callbackContext .error ("Unsupported action on Android" );
507
536
return false ;
@@ -563,25 +592,21 @@ public MeasureActionThread(String eventName, double revenue, String currency, St
563
592
@ Override
564
593
public void run () {
565
594
if (tracker != null ) {
566
- // Set currency code if exists
567
- if (currency != null && currency .length () > 0 && !currency .equals ("null" )) {
568
- tracker .setCurrencyCode (currency );
569
- }
570
595
// If there are any event items, track with event item
571
596
if (eventItemList != null && eventItemList .size () > 0 ) {
572
597
if (receiptData != null && !receiptData .equals ("null" ) && receiptSignature != null && !receiptSignature .equals ("null" )) {
573
598
// Track with receipt data if not null
574
- tracker .measureAction (eventName , eventItemList , revenue , tracker . getCurrencyCode () , refId , receiptData , receiptSignature );
599
+ tracker .measureAction (eventName , eventItemList , revenue , currency , refId , receiptData , receiptSignature );
575
600
} else {
576
601
// Track with just event item
577
- tracker .measureAction (eventName , eventItemList , revenue , tracker . getCurrencyCode () , refId );
602
+ tracker .measureAction (eventName , eventItemList , revenue , currency , refId );
578
603
}
579
604
} else if (receiptData != null && receiptSignature != null ) {
580
- tracker .measureAction (eventName , null , revenue , tracker . getCurrencyCode () , refId , receiptData , receiptSignature );
605
+ tracker .measureAction (eventName , null , revenue , currency , refId , receiptData , receiptSignature );
581
606
} else if (refId != null && refId .length () > 0 ) {
582
- tracker .measureAction (eventName , revenue , tracker . getCurrencyCode () , refId );
607
+ tracker .measureAction (eventName , revenue , currency , refId );
583
608
} else {
584
- tracker .measureAction (eventName , revenue , tracker . getCurrencyCode () );
609
+ tracker .measureAction (eventName , revenue , currency );
585
610
}
586
611
cbc .success ();
587
612
} else {
0 commit comments