SDK Integration
Step 1: Import Unity Jar Resolver
Download
external-dependency-manager-1.2.164.unitypackagefrom the NetmeraPackages folder.Import the package into your Unity project.
Step 2: Import Firebase Messaging
Download
FirebaseMessaging.unitypackagefrom the NetmeraPackages folder.Import the package into your project.
Do not uncheck any files during import.
Step 3: Import Netmera
Download
netmera-unity-1.1.4.noads.unitypackagefrom the NetmeraPackages folder.Import it into your Unity project.
Step 4: Adding Netmera-Info.plist file
Add the
Netmera-Info.plistfile to your Assets folder.Do not move it from this path.
If needed, rename the
Netmera-Info.plist.examplefile by removing the.exampleextension. The sample file can be found here.Ensure the
Netmera-Info.plistfile includes the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>netmera_logging_disabled</key>
<false/>
<key>netmera_mobile_sdkkey</key>
<string>YOUR_MOBILE_SDK_KEY</string>
<!-- OPTIONALS-->
<key>netmera_popup_presentation_disabled</key>
<false/>
<key>netmera_optional_baseurl</key>
<string>YOUR_BASE_URL</string>
<key>netmera_app_group_name</key>
<string>YOUR_GROUP_NAME</string>
</dict>
</plist>Step 5: Android and iOS Specific Guides
The Step 5 is divided into two categories: Android or iOS.
1. Add a google-services.json File
google-services.json FileTo configure Firebase messaging for your Unity application, download the google-services.json file from the Firebase Console. Follow these steps:
Download the file from the Firebase Console.
Place the
google-services.jsonfile directly in your Unity project'sAssetsfolder.Note: The file path is important. Do not move it after placing it in the
Assetsfolder.
2. Using a Custom mainTemplate.gradle File
mainTemplate.gradle FileUnity uses the Unity Jar Resolver to manage dependencies, and it automatically integrates the necessary Firebase components when you import the FirebaseMessaging.unitypackage. You will need to enable custom gradle templates for the integration.
In the Unity Editor, go to Project Settings -> Publishing Settings.
Enable the following settings:
Enable Custom Main Gradle Template
Enable Custom Main Manifest
Enable Custom Gradle Properties Template
These settings will generate two gradle-related files in the Assets/Plugins/Android folder: gradleTemplate.properties and mainTemplate.gradle.
Open the
gradleTemplate.propertiesfile and append the following line:android.useAndroidX=true
3. Jar Resolver Settings
To configure the Unity Jar Resolver, follow these steps:
In the Unity Editor, go to Assets -> External Dependency Manager -> Android Resolver -> Settings.
Apply the following recommended settings (though some are optional):
Uncheck Enable Auto Resolution.
Uncheck Enable Resolution on Build.
Check Install Android Packages.
Check Explode AARs.
Check Patch AndroidManifest.xml.
Check Patch mainTemplate.gradle.
Check Patch gradleTemplate.properties.
Check Use Jetifier.
These settings ensure that the Android dependencies are resolved and handled properly.
4. Jar Resolver Resolve Process
After configuring the resolver, follow these steps to ensure all dependencies are correctly imported:
In the Unity Editor, go to Assets -> External Dependency Manager -> Android Resolver -> Resolve.
After the process completes, open the
mainTemplate.gradlefile and verify that the necessary libraries have been imported correctly.In the
dependencies {}section ofmainTemplate.gradle, you should see the following libraries (version numbers may vary):implementation 'com.google.android.gms:play-services-base:17.6.0' // From Firebase/Editor/AppDependencies.xml implementation 'com.google.android.gms:play-services-location:18.0.0' // From Netmera/Editor/NetmeraDependencies.xml implementation 'com.google.firebase:firebase-analytics:18.0.2' // From Firebase/Editor/MessagingDependencies.xml implementation 'com.google.firebase:firebase-app-unity:7.1.0' // From Firebase/Editor/AppDependencies.xml implementation 'com.google.firebase:firebase-common:19.5.0' // From Firebase/Editor/AppDependencies.xml implementation 'com.google.firebase:firebase-messaging:21.0.1' // From Firebase/Editor/MessagingDependencies.xml implementation 'com.google.firebase:firebase-messaging-unity:7.1.0' // From Firebase/Editor/MessagingDependencies.xmlIf any libraries are missing, try using Force Resolve instead of Resolve.
Note: If you encounter any duplicate class errors during the build, check for and remove duplicate dependencies.
5. Enabling Multidex
If your Unity app exceeds the 64K method limit for a single APK, you will need to enable Multidex.
Open the
mainTemplate.gradlefile and navigate to theandroid -> defaultConfigsection.Add the following line to enable Multidex:
multiDexEnabled trueNote: If your
minSDKversion is below 21, additional steps are required. You can find more details on enabling Multidex here.
6. Editing the AndroidManifest.xml File
AndroidManifest.xml FileThe AndroidManifest.xml file is a crucial configuration file for setting up Firebase and Netmera SDK integration. Follow these steps:
Open your Unity project’s MAIN AndroidManifest.xml file, which can be found at
Assets/Plugins/Android/AndroidManifest.xml.Add the following lines inside the
<application>tag to integrate Netmera and Firebase:<application android:name="com.netmera.unity.sdk.core.NetmeraCustomApp"> <meta-data android:name="netmera_mobile_sdkkey" android:value="Netmera Mobile SDK key string value. Copy It From Netmera Dashboard."/> <meta-data android:name="netmera_firebase_senderid" android:value="Firebase Sender ID as number. Copy it from Netmera Dashboard."/> <meta-data android:name="netmera_huawei_senderid" android:value="Huawei Sender ID as number. Copy it from Netmera Dashboard."/> <meta-data android:name="netmera_optional_baseurl" android:value=""/> <meta-data android:name="netmera_logging_disabled" android:value="false"/> <meta-data android:name="netmera_popup_presentation_disabled" android:value="false"/> </application>Note: If you cannot use the Netmera
Applicationclass, you will need to manually add this line to theonCreatemethod of your ownApplicationclass:NetmeraCustomApp.initNetmera(this);
By following these steps, you ensure that the integration between Firebase, Netmera, and Unity is correctly configured.
Step 6: Demo Scene
Navigate to Assets > Netmera > Demo > NetmeraDemoScene.
You can integrate this scene into your app to test the integration.
Step 7: Adding Prefab to your first Unity Scene
In your Unity scene, import the prefab located at: Assets > Netmera > Demo > Prefabs > NetmeraManager.
This prefab contains the
NetmeraGameObjectscript, which demonstrates SDK methods.Do not destroy this object while switching between Unity scenes. It should persist throughout the app.
In the
Awake()method of your scene, call:
NetmeraCore.Instance.Init(this);Netmera Unity Sample Methods
1. Logging Configuration
The loggingEnabled boolean controls whether logging is enabled in the Netmera SDK. This can be set in the Unity editor to toggle logging functionality.
[SerializeField] private bool loggingEnabled = true;2. Initialization (Awake Method)
In the Awake method, the following actions are performed:
Stack trace logging for regular log messages is disabled.
The
NetmeraGameObjectis set to persist across scene loads usingDontDestroyOnLoad.The
Test_Initmethod is called to initialize the Netmera SDK.
private void Awake()
{
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
DontDestroyOnLoad(gameObject);
Test_Init();
}3. Initialization Method: Test_Init
Test_InitThe Test_Init method initializes the Netmera SDK. If the NetmeraCore instance is available, logging is configured based on the loggingEnabled flag, and the SDK is initialized.
public void Test_Init()
{
if (NetmeraCore.Instance == null)
{
return;
}
NetmeraCore.Instance.LoggingEnabled = loggingEnabled;
NetmeraCore.Instance.Init(this);
}4. Sample SDK Method Calls
Sending an Event
The following method sends an event to the Netmera SDK, with sample data provided for event category and count.
public void Test_SendEvent()
{
JSONObject obj = new JSONObject();
obj["ea"] = "valuesample";
obj["ec"] = 10;
NetmeraCore.Instance.SendEvent("zzl", obj);
}Updating User Information
This method creates a NetmeraUser object and updates the user's birthday and city information.
public void Test_UpdateUser()
{
NetmeraUser user = new NetmeraUser();
user.SetBirthday("1980", "06", "26");
user.SetCity("Istanbul");
NetmeraCore.Instance.UpdateUser(user);
}Fetching Inbox Items
The Test_FetchInbox method fetches inbox items, with a filter for "read or unread" push notifications.
public void Test_FetchInbox()
{
List<string> categories = new List<string>() {};
NetmeraCore.Instance.FetchInbox(20, NetmeraEnum.PushStatus.ReadOrUnread, categories, true);
}Fetching the Next Page of Inbox Items
This method fetches the next page of inbox items.
public void Test_FetchNextPage()
{
NetmeraCore.Instance.FetchNextPage();
}Destroying the SDK Instance
The Test_Destroy method destroys the current Netmera SDK instance.
public void Test_Destroy()
{
NetmeraCore.Instance.Destroy();
}Enabling Popup Presentation
This method allows for enabling or disabling popup presentations for push notifications.
public void Test_EnablePopupPresentation(bool isEnabled)
{
NetmeraCore.Instance.EnablePopupPresentation(isEnabled);
}Getting Push Notification Status Count
This method retrieves the count of push notifications based on their status (read/unread).
public void Test_GetStatusCount()
{
NetmeraCore.Instance.GetStatusCount(NetmeraEnum.PushStatus.ReadOrUnread);
}Changing the Status of Inbox Items
The Test_ChangeInboxItemStatuses method allows for changing the status of specific inbox items.
public void Test_ChangeInboxItemStatuses()
{
NetmeraCore.Instance.ChangeInboxItemStatuses(1, 2, NetmeraEnum.PushStatus.Deleted);
}Requesting Location Permissions
The Test_RequestPermissionsForLocation method requests permissions to access the user’s location.
public void Test_RequestPermissionsForLocation()
{
NetmeraCore.Instance.RequestPermissionsForLocation();
}Changing the Status of All Inbox Items
This method changes the status of all inbox items to "deleted."
public void Test_ChangeAllInboxItemStatuses()
{
NetmeraCore.Instance.ChangeAllInboxItemStatuses(NetmeraEnum.PushStatus.Deleted);
}5. Callback Methods
The class implements several callback methods for handling events related to push notifications and inbox operations. Each callback is currently a placeholder, but you can add custom logic to process the events as needed.
Push Notifications:
OnPushRegister: Triggered when the device registers for push notifications.OnPushReceive: Triggered when a push notification is received.OnPushOpen: Triggered when a push notification is opened by the user.OnPushDismiss: Triggered when a push notification is dismissed.OnPushButtonClicked: Triggered when a button in a push notification is clicked.
Inbox Operations:
OnInboxFetchSuccess: Triggered when inbox items are successfully fetched.OnInboxFetchFail: Triggered when there is a failure to fetch inbox items.OnInboxNextPageFetchSuccess: Triggered when the next page of inbox items is successfully fetched.OnInboxNextPageFetchFail: Triggered when there is a failure to fetch the next page of inbox items.OnInboxStatusChangeSuccess: Triggered when the status of inbox items is successfully changed.OnInboxStatusChangeFail: Triggered when there is a failure to change the status of inbox items.OnInboxStatusCount: Triggered when the count of inbox items with a specific status is retrieved.
Last updated
Was this helpful?