Advanced
Location Tracking
Smartech SDK allows the user to track location using setUserLocation()
method which takes context, Latitude, and Longitude as parameters.
NOTE:
Data type of Latitude and Longitude should be double.
SmartechSDK.setUserLocation(LATITUDE_DOUBLE_VALUE, LONGITUDE_DOUBLE_VALUE);
// Sample code for reference purpose only
SmartechSDK.setUserLocation(19.0760, 72.8777);
Get GUID
To get the GUID that is used by Smartech SDK to identify the user, you can call the getDeviceGuid()
method.
SmartechSDK.getDeviceGuid((error, deviceGuid) => {
//Grab the deviceGuid
});
GDPR Compliance
Smartech believes privacy is a fundamental human right, which is why Smartech SDK has methods to opt-out from tracking user's events, displaying in-app messages, and receiving push notifications sent from the panel.
Opt-Out From Tracking Events, displaying In-App Messaging and receiving Push Notification
To opt-out for tracking of events, display of in-app, and receiving push notifications developer needs to implement the following methods and pass false in the argument.
//Used for tracking
SmartechSDK.optTracking(false);
//Used for In-App
SmartechSDK.optInAppMessage(false);
//Used for Push Notification
SmartechSDK.optPushNotification(false);
To enable tracking of events, display of in-app, and receiving push notifications developer needs to pass true.
//Used for tracking
SmartechSDK.optTracking(true);
//Used for In-App
SmartechSDK.optInAppMessage(true);
//Used for Push Notification
SmartechSDK.optPushNotification(true);
To Fetch Advertising Id
If an app wants to fetch Advertising Id of the device using Smartech SDK, follow the steps below.
Adding Dependency
implementation 'com.google.android.gms:play-services-ads:17.2.1'
Adding Meta tags
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR_ADMOB_APP_ID"/>
<meta-data
android:name="SMT_USE_AD_ID"
android:value="1_OR_0_VALUE"/>
Note:
- To get "AdMob App ID" please refer this: https://developers.google.com/admob/android/quick-start
- This tag accepts either ‘0’ or ‘1’ as value. If an app wants Smartech SDK to fetch Advertising Id of the device, use ‘1’ as value otherwise use '0'.
Fetching Deeplink and CustomPayload (Android)
Use Case 1: If the App is in the Background or in the Killed state.
The Deeplink data will be received in the Launcher activity of App.
Write the following code in launcher activity.
Bundle bundleExtra = getIntent().getExtras();
if (bundleExtra != null) {
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
String deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK);
// TODO: Use the deepLinkValue variable to navigate the user.
} else {
Log.v("Activity", "does not have deeplink path.");
}
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)) {
String customPayloadvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD);
} else {
Log.v("Activity", "does not have custom payload.");
}
}
val bundleExtra = intent.extras
if (bundleExtra != null) {
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
val deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)
// TODO: Use the deepLinkValue variable to navigate the user.
} else {
Log.v("Activity", "Does not have deeplink path.")
}
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)) {
val customPayloadvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)
} else {
Log.v("Activity", "Does not have custom payload.")
}
}
Use Case 2: If Application is in the foreground and the user clicks on notification.
In this case, App has to register a BroadcastReceiver with the following intent filter and the data will be received in the onReceive method of the service class.
Register the BroadcastReceiver inside the Application class.
DeeplinkReceiver deeplinkReceiver = new DeeplinkReceiver();
IntentFilter filter = new IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK");
context.registerReceiver(deeplinkReceiver, filter);
val deeplinkReceiver = DeeplinkReceiver()
val filter = IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK")
registerReceiver(deeplinkReceiver, filter)
Implementation for BroadcastReciever class.
public class DeeplinkReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundleExtra = getIntent().getExtras();
if (bundleExtra != null) {
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
String deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK);
// TODO: Use the deepLinkValue variable to navigate the user.
} else {
Log.v("Activity", "does not have deeplink path.");
}
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)) {
String customPayloadvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD);
} else {
Log.v("Activity", "does not have custom payload.");
}
}
}
}
class DeeplinkReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val bundleExtra = intent.extras
if (bundleExtra != null) {
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
val deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)
// TODO: Use the deepLinkValue variable to navigate the user.
} else {
Log.v("Activity", "Does not have deeplink path.")
}
if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)) {
val customPayloadvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)
} else {
Log.v("Activity", "Does not have custom payload.")
}
}
}
}
Implementing Deeplink In The React Native (iOS)
Implement this method in the Appdelegate file
- (void)handleDeeplinkActionWithURLString:(NSString *)deeplinkURLString andCustomPayload:(NSDictionary *_Nullable)customPayload {
NSMutableDictionary *smtData = [[NSMutableDictionary alloc] init];
smtData[kSMTDeeplinkIdentifier] = deeplinkURLString ? deeplinkURLString : @"";
smtData[kSMTCustomPayloadIdentifier] = customPayload ? customPayload : @{};
[[NSNotificationCenter defaultCenter] postNotificationName:kSMTDeeplinkNotificationIdentifier object:nil userInfo:smtData];
}
Updated almost 4 years ago