You can receive and read the server responses from the TUNE SDK calls to help diagnose and debug your SDK implementation. These responses can provide helpful error messages and success notifications.
The following sample code shows a class that implements the TuneListener interface and outputs the server response(s) to LogCat. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the TuneListener interface and outputs the server response(s) to LogCat. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MATResponse interface and outputs the server response(s) to LogCat. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MATResponse interface and outputs the server response(s) to LogCat. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MATResponse interface and outputs the server response(s) to LogCat. Override the methods with your own to make use of the server responses.
The following sample code shows how to use the Tune debug handler. Route the debug log message to any log system.
The following sample code shows a class that implements the TuneDelegate protocol and logs the responses to the console. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the TuneDelegate protocol and logs the responses to the console. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MobileAppTrackerDelegate protocol and logs the responses to the console. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MobileAppTrackerDelegate protocol and logs the responses to the console. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MobileAppTrackerDelegate protocol and logs the responses to the console. Override the methods with your own to make use of the server responses.
The measurement functions in the JavaScript SDK accept callback functions in their arguments.
The following sample code shows a class that implements the MATResponse interface and outputs the response(s) to the console. Override the methods with your own to make use of the server responses.
This setting causes MAT to log the server responses to the console.
This setting causes MAT to log the server responses to the console.
This setting causes MAT to log the server responses to the console.
This setting causes MAT to log the server responses to the console.
The following sample code shows a Unity script that implements the MobileAppTrackerDelegate callback methods and logs the responses to the console. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MobileAppTrackerDelegate interface and logs the responses to the console. Override the methods with your own to make use of the server responses.
The following sample code shows a class that implements the MobileAppTrackerDelegate interface and logs the responses to the console. Override the methods with your own to make use of the server responses.
MobileAppTracker.instance.setDelegate(true);
MobileAppTracker.instance.setDelegate(true);
public class MyTuneListener implements TuneListener {
@Override
public void enqueuedActionWithRefId(String refId) {
Log.d("TUNE", "enqueuedActionWithRefId " + refId);
}
@Override
public void enqueuedRequest(String url, JSONObject postData) {
Log.d("TUNE", "enqueuedRequest " + url + " " + postData);
}
@Override
public void didSucceedWithData(JSONObject data) {
Log.d("TUNE", "didSucceedWithData " + data);
}
@Override
public void didFailWithError(JSONObject error) {
Log.d("TUNE", "didFailWithError " + error);
}
public class MyTuneListener implements TuneListener {
@Override
public void enqueuedActionWithRefId(String refId) {
// call has been queued, will be sent later
}
@Override
public void didSucceedWithData(JSONObject data) {
Log.d("TUNE.success", data.toString());
}
@Override
public void didFailWithError(JSONObject error) {
Log.d("TUNE.failure", error.toString());
}
}
public class MyMATResponse implements MATResponse {
@Override
public void enqueuedActionWithRefId(String refId) {
// call has been queued, will be sent later
}
@Override
public void didSucceedWithData(JSONObject data) {
Log.d("MAT.success", data.toString());
}
@Override
public void didFailWithError(JSONObject error) {
Log.d("MAT.failure", error.toString());
}
@Override
public void didReceiveDeeplink(String deeplink) {
// retrieve full deferred deep link
}
}
public class MyMATResponse implements MATResponse {
@Override
public void enqueuedActionWithRefId(String refId) {
// call has been queued, will be sent later
}
@Override
public void didSucceedWithData(JSONObject data) {
Log.d("MAT.success", data.toString());
}
@Override
public void didFailWithError(JSONObject error) {
Log.d("MAT.failure", error.toString());
}
}
public class MyMATResponse implements MATResponse {
@Override
public void didSucceedWithData(JSONObject data) {
Log.d("MAT.success", data.toString());
}
@Override
public void didFailWithError(JSONObject error) {
Log.d("MAT.failure", error.toString());
}
}
PluginParam pDelegate(true);
AppDelegate::mat()->callFuncWithParam("setDelegate", &pDelegate, NULL);
//FOR SWIFT
Tune.setDebugLogCallback { (message:String) in
// prints to the debugger log
print(message)
// prints to the debugger log and device log, does not redact anything
//NSLog("%@", message)
// prints to the debugger log and device log, redacts Strings by default
// iOS 10+
//os_log("%@", message!)
}
// Enables verbose debug messages, this very detailed and may include PII
Tune.setDebugLogVerbose(true)
//FOR OBJECTIVE-C
[Tune setDebugLogCallback:^(NSString * _Nonnull logMessage) {
NSLog(@"%@", logMessage);
}];
[Tune setDebugLogVerbose:YES];
@import Tune;
@interface MyDelegate () <TuneDelegate>
@end
@implementation MyDelegate
#pragma mark - TuneDelegate Methods
- (void)tuneEnqueuedRequest:(nullable NSString *)url postData:(nullable NSString *)post;
{
NSLog(@"TUNE.enqueued request: url = %@, post data = %@", url, post);
}
- (void)tuneDidSucceedWithData:(nullable NSData *)data;
{
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"TUNE.success: %@", response);
}
- (void)tuneDidFailWithError:(nullable NSError *)error;
{
NSLog(@"TUNE.failure: %@", error);
}
@end
#import <MobileAppTracker/MobileAppTracker.h>
@interface MyMATDelegate () <MobileAppTrackerDelegate>
@end
@implementation MyMATDelegate
#pragma mark - MobileAppTrackerDelegate Methods
- (void)mobileAppTrackerEnqueuedActionWithReferenceId:(NSString *)referenceId
{
// call has been queued, will be sent later
}
- (void)mobileAppTrackerDidSucceedWithData:(NSData *)data
{
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"MAT.success: %@", response);
}
- (void)mobileAppTrackerDidFailWithError:(NSError *)error
{
NSLog(@"MAT.failure: %@", error);
}
- (void)mobileAppTrackerDidReceiveDeeplink:(NSString *)deeplink
{
// retrieve full deferred deep link
}
@end
#import <MobileAppTracker/MobileAppTracker.h>
@interface MyDelegate () <TuneDelegate>
@end
@implementation MyDelegate
#pragma mark - TuneDelegate Methods
- (void)tuneEnqueuedActionWithReferenceId:(NSString *)referenceId
{
// call has been queued, will be sent later
}
- (void)tuneDidSucceedWithData:(NSData *)data
{
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"TUNE.success: %@", response);
}
- (void)tuneDidFailWithError:(NSError *)error
{
NSLog(@"TUNE.failure: %@", error);
}
@end
#import <MobileAppTracker/MobileAppTracker.h>
@interface MyMATDelegate () <MobileAppTrackerDelegate>
@end
@implementation MyMATDelegate
#pragma mark - MobileAppTrackerDelegate Methods
- (void)mobileAppTrackerEnqueuedActionWithReferenceId:(NSString *)referenceId
{
// call has been queued, will be sent later
}
- (void)mobileAppTrackerDidSucceedWithData:(NSData *)data
{
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"MAT.success: %@", response);
}
- (void)mobileAppTrackerDidFailWithError:(NSError *)error
{
NSLog(@"MAT.failure: %@", error);
}
@end
#import <MobileAppTracker/MobileAppTracker.h>
@interface MyMATDelegate () <MobileAppTrackerDelegate>
@end
@implementation MyMATDelegate
#pragma mark - MobileAppTrackerDelegate Methods
- (void)mobileAppTrackerDidSucceedWithData:(NSData *)data
{
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"MAT.success: %@", response);
}
- (void)mobileAppTrackerDidFailWithError:(NSError *)error
{
NSLog(@"MAT.failure: %@", error);
}
@end
function myCallback(data) {
console.log("MAT server response: " + JSON.stringify(data));
};
// as a key in the request options:
MobileAppTracker.measureAction({eventName: "purchase",
callback: myCallback});
// as a second argument to the function:
MobileAppTracker.measureAction({eventName: "purchase"}, myCallback);
function myCallback(data) {
console.log("MAT server response: " + JSON.stringify(data));
};
MobileAppTracker.trackSession(myCallback);
MobileAppTracker.trackAction(eventName, revenue, currency, refId, eventItems, myCallback);
window.plugins.tunePlugin.setDelegate(true, successCallback, errorCallback);
mat.setDelegate(successCallback, errorCallback, true);
mat.setDelegate(successCallback, errorCallback, true);
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class TuneListener : MonoBehaviour
{
public void trackerDidSucceed (string data)
{
#if UNITY_IOS
print ("TuneListener trackerDidSucceed: " + DecodeFrom64 (data));
#endif
#if (UNITY_ANDROID || UNITY_WP8 || UNITY_METRO)
print ("TuneListener trackerDidSucceed: " + data);
#endif
}
public void trackerDidFail (string error)
{
print ("TuneListener trackerDidFail: " + error);
}
public void trackerDidEnqueueUrl (string url)
{
print ("TuneListener trackerDidEnqueueUrl: " + url);
}
/// <summary>
/// The method to decode base64 strings.
/// </summary>
/// <param name="encodedData">A base64 encoded string.</param>
/// <returns>A decoded string.</returns>
public static string DecodeFrom64 (string encodedString)
{
print ("TuneListener.DecodeFrom64(string)");
return System.Text.Encoding.UTF8.GetString (System.Convert.FromBase64String (encodedString));
}
}
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class MATDelegateScript : MonoBehaviour
{
public void trackerDidSucceed (string data)
{
print ("MATDelegateScript trackerDidSucceed: " + DecodeFrom64 (data));
}
public void trackerDidFail (string error)
{
print ("MATDelegateScript trackerDidFail: " + error);
}
public void trackerDidEnqueueRequest (string refId)
{
print ("MATDelegateScript trackerDidEnqueueRequest: " + refId);
}
///
/// The method to decode base64 strings.
///
///A base64 encoded string.
/// A decoded string.
public static string DecodeFrom64 (string encodedString)
{
print ("MATDelegateScript.DecodeFrom64(string)");
return System.Text.Encoding.UTF8.GetString (System.Convert.FromBase64String (encodedString));
}
}
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class MATDelegateScript : MonoBehaviour
{
public void trackerDidSucceed (string data)
{
print ("MATDelegateScript trackerDidSucceed: " + DecodeFrom64 (data));
}
public void trackerDidFail (string error)
{
print ("MATDelegateScript trackerDidFail: " + error);
}
public void trackerDidEnqueueRequest (string refId)
{
print ("MATDelegateScript trackerDidEnqueueRequest: " + refId);
}
///
/// The method to decode base64 strings.
///
///A base64 encoded string.
/// A decoded string.
public static string DecodeFrom64 (string encodedString)
{
print ("MATDelegateScript.DecodeFrom64(string)");
return System.Text.Encoding.UTF8.GetString (System.Convert.FromBase64String (encodedString));
}
}
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class MATDelegateScript : MonoBehaviour
{
public void trackerDidSucceed (string data)
{
print ("MATDelegateScript trackerDidSucceed: " + DecodeFrom64 (data));
}
public void trackerDidFail (string error)
{
print ("MATDelegateScript trackerDidFail: " + error);
}
public void trackerDidEnqueueRequest (string refId)
{
print ("MATDelegateScript trackerDidEnqueueRequest: " + refId);
}
///
/// The method to decode base64 strings.
///
///A base64 encoded string.
/// A decoded string.
public static string DecodeFrom64 (string encodedString)
{
print ("MATDelegateScript.DecodeFrom64(string)");
return System.Text.Encoding.UTF8.GetString (System.Convert.FromBase64String (encodedString));
}
}
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class MATDelegateScript : MonoBehaviour
{
public void trackerDidSucceed (string data)
{
print ("MATDelegateScript trackerDidSucceed: " + DecodeFrom64 (data));
}
public void trackerDidFail (string error)
{
print ("MATDelegateScript trackerDidFail: " + error);
}
///
/// The method to decode base64 strings.
///
///A base64 encoded string.
/// A decoded string.
public static string DecodeFrom64 (string encodedString)
{
print ("MATDelegateScript.DecodeFrom64(string)");
return System.Text.Encoding.UTF8.GetString (System.Convert.FromBase64String (encodedString));
}
}
public class MyMATResponse : MATResponse
{
public void EnqueuedActionWithRefId(string refId)
{
// call has been queued, will be sent later
}
public void DidSucceedWithData(string response)
{
Debug.WriteLine("MAT.success: " + response);
}
public void DidFailWithError(string error)
{
Debug.WriteLine("MAT.failure " + error);
}
}
public class MyMATResponse : MATResponse
{
public void DidSucceedWithData(string response)
{
Debug.WriteLine("MAT.success: " + response);
}
public void DidFailWithError(string error)
{
Debug.WriteLine("MAT.failure " + error);
}
}
public class TestMATDelegate : MobileAppTrackerDelegate
{
public override void MobileAppTrackerDidSucceed (NSData data)
{
Console.WriteLine ("MAT DidSucceed: " + NSString.FromData(data, NSStringEncoding.UTF8));
}
public override void MobileAppTrackerDidFail (NSError error)
{
Console.WriteLine ("MAT DidFail: error = " + error.Code + ", " + error.LocalizedDescription);
}
public override void MobileAppTrackerEnqueuedAction (string referenceId)
{
Console.WriteLine ("MAT EnqueuedAction: advertiserRefId = " + referenceId);
}
}
public class TestMATDelegate : MobileAppTrackerDelegate
{
public override void MobileAppTrackerDidSucceed (MobileAppTracker tracker, NSData data)
{
Console.WriteLine ("MAT DidSucceed: " + data.ToString ());
}
public override void MobileAppTrackerDidFail (MobileAppTracker tracker, NSError error)
{
Console.WriteLine ("MAT DidFail: " + error.ToString());
}
}
Unable to load code example.
Select a preferred platform.
Create a new instance of this class and register it using the setListener method:
Create a new instance of this class and register it using the setListener method:
Create a new instance of this class and register it using the setMATResponse method:
Create a new instance of this class and register it using the setMATResponse method:
Create a new instance of this class and register it using the setMATResponse method:
Create a new instance of this class and register it using the setDelegate method:
Create a new instance of this class and register it using the setDelegate method:
Create a new instance of this class and register it using the setDelegate method:
Create a new instance of this class and register it using the setDelegate method:
Create a new instance of this class and register it using the setDelegate method:
Create a new instance of this class and register it using the SetMATResponse method:
Call the setter to enable the delegate functionality.
Create a new instance of this subclass of MobileAppTrackerDelegate and register it using the SetDelegate setter method:
Create a new instance of this class and register it using the Delegate property:
MyTuneListener listener = new MyTuneListener();
Tune.getInstance().setListener(listener);
MyTuneListener listener = new MyTuneListener();
Tune.getInstance().setListener(listener);
MyMATResponse response = new MyMATResponse();
MobileAppTracker.getInstance().setMATResponse(response);
MyMATResponse response = new MyMATResponse();
MobileAppTracker.getInstance().setMATResponse(response);
MyMATResponse response = new MyMATResponse();
MobileAppTracker.getInstance().setMATResponse(response);
MyDelegate *object = [[MyDelegate alloc] init];
[Tune setDelegate:object]; // Note: the delegate object is not retained
MyMATDelegate *object = [[MyMATDelegate alloc] init];
[MobileAppTracker setDelegate:object]; // Note: the delegate object is not retained
MyDelegate *object = [[MyDelegate alloc] init];
[Tune setDelegate:object]; // Note: the delegate object is not retained
MyMATDelegate *object = [[MyMATDelegate alloc] init];
[MobileAppTracker setDelegate:object]; // Note: the delegate object is not retained
MyMATDelegate *object = [[MyMATDelegate alloc] init];
[MobileAppTracker setDelegate:object]; // Note: the delegate object is not retained
Tune.setDelegate(true);
setDelegate(true);
setDelegate(true);
setDelegate(true);
setDelegate(true);
MyMATResponse response = new MyMATResponse();
mobileAppTracker.SetMATResponse(response);
MyMATResponse response = new MyMATResponse();
mobileAppTracker.SetMATResponse(response);
TestMATDelegate matDelegate = new TestMATDelegate();
MobileAppTracker.SetDelegate(matDelegate);
private MobileAppTracker mat;
mat = MobileAppTracker.SharedManager;
mat.Delegate = new TestMATDelegate();
Unable to load code example.
Select a preferred platform.
Now when a TUNE request completes, the code in your custom TuneListener methods is run – outputting to LogCat in this example.
Now when a TUNE request completes, the code in your custom TuneListener methods is run – outputting to LogCat in this example.
Now when a MAT request completes, the code in your custom MATResponse methods is run – outputting to LogCat in this example.
Now when a MAT request completes, the code in your custom MATResponse methods is run – outputting to LogCat in this example.
Now when a MAT request completes, the code in your custom MATResponse methods is run – outputting to LogCat in this example.
Now when a TUNE request completes, the code in your custom TuneDelegate methods is run – outputting to the console in this example.
Now when a TUNE request completes, the code in your custom TuneDelegate methods is run – outputting to the console in this example.
Now when a MAT request completes, the code in your custom MobileAppTrackerDelegate methods is run – outputting to the console in this example.
Now when a MAT request completes, the code in your custom MobileAppTrackerDelegate methods is run – outputting to the console in this example.
Now when a MAT request completes, the code in your custom MobileAppTrackerDelegate methods is run – outputting to the console in this example.
Now when a MAT request completes, the code in your custom callback functions is run – outputting to the console in this example.
Now when a MAT request completes, the code in your custom MATResponse methods is run – outputting to the debug logs in this example.
The TUNE plugin uses the name “TuneListener” when sending delegate callbacks. Make sure you create a GameObject by the name “TuneListener” in your Unity project, and attach the above script (that implements the TUNE delegate callback methods) to that GameObject. To do this automatically, you can also select TUNE -> Setup > Delegate Callbacks > Create TuneListener Object from your Unity menu.
Now when a MAT request completes, the code in your custom TestMATDelegate methods is run – outputting to the console in this example.
Now when a MAT request completes, the code in your custom TestMATDelegate methods is run – outputting to the console in this example.