Getting started with MRGSFirebase🔗
MRGSFirebase integration requires a few simple steps:
Step 1. Import the MRGSFirebase module🔗
-
Add MRGSFirebase module
Unity:
Adding to the project (general instruction)
Step 1. Add Sources
To add MRGS to a project via the Unity Package Manager (available from Unity 2018+) simply add a
scopedRegistriessection to thePackages/manifest.jsonfile by adding the following entry:{ "dependencies": { ... }, "scopedRegistries": [ { "name": "MRGS", "url": "https://mrgs-nexus.my.games/repository/mrgs-uninty-plugins/", "scopes": [ "games.my.mrgs" ] } ] }Alternatively, you can click
Edit -> Project Settings -> Package Manager -> '+' in scoped registry section, and fill in the fields according to the data above.Step 2. Add dependency
- Click
Window -> Package Manager -> select 'Packages: MyRegistries' from dropdown list, select packageMRGSFirebasefrom the list, then click "Install" - Import the module:
using MRGS;
- Download the latest version of the library. Unzip the archive.
- (For unitypackage integration) In Unity, click
Assets -> Import Package -> Custom Package, and select thegames.my.mrgs.firebase.unitypackagepackage from the downloaded archive. - (For tgz integration) In Unity, click
Window -> Package Manager -> '+' -> Add package from tarball, and select thegames.my.mrgs.firebase-<version> package. tgzfrom the downloaded archive. - Import the module:
using MRGS;
iOS:
Adding to the project (general instruction)
Step 1: Add dependencies
Via Package collection
- In Xcode select File > Add Packages
- Select "+" > "Add Swift Package Collection"
- Insert URL:
https://mrgs-nexus.my.games/repository/ios-sdks/MRGSPackageCollection.json - Select module MRGSFirebase from "MRGS Package Collection".
- Or you can select "MRGS" package from "MRGS Package Collection" (contains all mrgs modules as products) and then select "MRGS/Firebase" product only.
Individual packages
- In Xcode select File > Add Packages
- In the search bar at the top right, paste the URL:
https://mrgs-gitea.my.games/mrgs/mrgsfirebase-ios-sdk.git - Add a module to your project
- Or you can paste the url
https://mrgs-gitea.my.games/mrgs/ios-sdks.gitto include the "MRGS" package which contains all mrgs modules as products and then select only the product" MRGS/Firebase".
Step 2: Add support for ObjectiveC categories
- Set the
-ObjCflag in the "Other linker Flags" field in the project settings. - Import the module in code:
@import MRGServiceKit;or@import MRGSFirebase;or#import <MRGSFirebase/MRGSFirebase.h>
Step 1. Add Sources
In your podfile, add sources to the top of the file:
source 'https://github.com/CocoaPods/Specs.git' # For main repo source 'https://mrgs-gitea.my.games/mrgs/cocoapods-specs.git' # For MRGS repoStep 2: Add dependencies
Add the latest version of MRGSFirebase to target:
To add via subspecs:
To add via individual modules:
To add all mrgs modules:
Step 3: Install dependencies
- Run
pod install(orpod install --repo-updateif necessary) - Import the module in code:
@import MRGServiceKit;or@import MRGSFirebase;or#import <MRGSFirebase/MRGSFirebase.h>
Step 1: Add dependencies
Add the dependency to your Cartfile:
Step 2: Install dependencies
- Run
carthage update --use-xcframeworks - Add downloaded frameworks to your project (make sure "do not embed" option is enabled)
- Set the
-ObjCflag in the "Other linker Flags" field in the project settings. - Import the module in code:
@import MRGServiceKit;or@import MRGSFirebase;or#import <MRGSFirebase/MRGSFirebase.h>
- Download the latest version of the library. Unzip the archive.
-
Add
MRGSFirebase.xcframeworkfrom the downloaded archive to your project (Drag the libraries to the "Linked frameworks and Libraries" section) (Also contains MRGSFirebase.framework for compatibility - fat framework) -
Set the
-ObjCflag in the "Other linker Flags" field in the project settings. - Import the module in code:
@import MRGSFirebase;or#import <MRGSFirebase/MRGSFirebase.h> - Also, you can add the
MRGServiceKit.handmodule.modulemapfiles from the archive to your project, or specify the path to them in the project settings in theBuild Settings -> Header search pathssection. Now, instead of importing each of our frameworks separately, you can only import one header file:@import MRGServiceKit;
Android:
Add a dependency in the root
build.gradlefile:dependencies { // Root gradle //... classpath 'com.android.tools.build:gradle:7.4.2' // Add it. classpath 'com.google.gms:google-services:4.3.13' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }Add a dependency in the project
build.gradlefile:Copy the MRGSFirebase.aar file to the "libs" directory of your project. Add the necessary dependencies to the "build.gradle" file.
- Click
Huawei Store
Please note that Huawei no longer supplies Google Service on its devices, which makes Firebase unavailable.
Step 2. Set up the application on the Firebase website🔗
- On the Firebase website, create an application using the Google Firebase documentation.
- Open the application settings section.
Application settings section

- Download files
google-services.jsonfor android andGoogleService-Info.plistfor iOS.
Configuration files download


Step 3. Add downloaded files to the project🔗
Unity🔗
For Android:
Copy the file google-services.json in Assets/Plugins/Android/assets. During the build assembly, Unity will place the google-services.json file in the src/main/assets directory of the Android project. You need to configure the build so that this file is in the root of the assembled Android project. The better way to do this is by editing a gradle file (See the Unity< your_version > tab) in the Assets/Plugins/Android directory and placing the following code at the very end of the file:
Unity 2018
Edit the baseProjectTemplate.gradle file.
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
// Add it.
classpath 'com.google.gms:google-services:4.3.13'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Edit the mainTemplate.gradle file.
Unity 2019
Edit the baseProjectTemplate.gradle file.
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
// Add it.
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Edit the launcherTemplate.gradle file.
Attention
<YOUR_APP_PACKAGE_NAME> is the package name of your Android project, and the string apply plugin: 'com.google.gms.google-services' is needed to parse the file google-services.json.
For iOS:
Copy the file GoogleService-Info.plist in Assets/Plugins/iOS. MRGS will automatically add this file to the Xcode project in the "Copy Bundle Resources" section during assembly. In case you do not want to put the file in Assets/Plugins/iOS, you can put it anywhere, but in this case you will need to add a copy of this file (using PostBuildProcess) to the Xcode project, the code below is snippet for files copying:
Example of copying a file to a project using PostBuildProcess
public class MRGSPostBuildExample
{
private const string ConfigsPath = "Assets/Path/Configs";
[PostProcessBuild]
public static void PostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS)
{
#if UNITY_IOS
string projPath = PBXProject.GetPBXProjectPath(path);
PBXProject proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
#if UNITY_2019_3_OR_NEWER
string projectTarget = proj.GetUnityMainTargetGuid();
#else
string targetName = PBXProject.GetUnityTargetName();
string projectTarget = proj.TargetGuidByName(targetName);
#endif
AddLocalFile(path, proj, projectTarget, ConfigsPath, "GoogleService-Info.plist");
File.WriteAllText(projPath, proj.WriteToString());
#endif
}
}
#if UNITY_IOS
private static void AddLocalFile(string buildPath, PBXProject proj, string targetName, string fileDir, string fileName)
{
var filePath = Path.Combine(fileDir, fileName);
File.Copy(filePath, Path.Combine(buildPath, fileName), true);
proj.AddFileToBuild(targetName, proj.AddFile(fileName, fileName, PBXSourceTree.Source));
}
#endif
}
iOS🔗
Add the file GoogleService-Info.plist (downloaded earlier from the Firebase admin panel) to the project (Copy Bundle Resources section in the Build Phases tab)
Android🔗
Copy the google-services.json file to the root folder of your project. Usually, it's the app directory. Edit the file build.gradle and add the following line at the end of the file:
Step 4. Sending events🔗
User properties🔗
User properties are attributes you define to describe segments of your user base, such as language preference or geographic location.
To set user properties for sending to firebase analytics, use the method:
Custom events🔗
Use the following API to send your own events:
Auto-collected events🔗
MRGS automatically monitors and sends additional launch and payment events to Firebase.
-
Regardless of the use of other modules, MRGS will automatically send events:
Event Sending condition mrgs_cumulative_session_time_30min Sent when the user has been in the application for more than 30 minutes. Dispatched once. mrgs_cumulative_session_time_60min Sent when the user has been in the application for more than 60 minutes. Dispatched once. mrgs_cumulative_session_time_120min Sent when the user has been in the application for more than 120 minutes. Dispatched once. mrgs_cumulative_session_time_180min Sent when the user has been in the application for more than 180 minutes. Dispatched once. -
MRGS will also send an additional list of payment events, but only if one of the conditions is met:
- Using MRGSBilling for purchasing.
- Using MRGSMetrics to notify MRGS about payments.
- Using Auto-tracking of payments for iOS.
These conditions are not mandatory, they can be omitted if you do not need payment event data.
Event Sending condition Purchases1D Dispatched upon purchase within one day of user registration Purchases7D Dispatched upon purchase within one week of user registration Purchases14D Dispatched upon purchase within two weeks of user registration Purchases28D Sent upon purchase within one month of user registration Purchases90D Dispatched upon purchase within three months of user registration UniquePurchases1D Sent for a purchase within one day of the user's registration, if that purchase was the first purchase they made UniquePurchases7D Sent for a purchase within one week of a user's registration if that purchase was the first purchase they made UniquePurchases14D Sent for a purchase within two weeks of a user's registration if that purchase was the first purchase they made UniquePurchases28D Sent for a purchase within one month of the user's registration, if that purchase was the first purchase they made UniquePurchases90D Sent for a purchase within three months of a user registered if the purchase was the first purchase they made mrgs_valid_inapp_purchase Sent after the purchase has been validated, and the payment information is also added to the event (sku, price, currency) mrgs_valid_inapp_5_dollars_plus Dispatched when any purchase exceeds $ 5. mrgs_valid_inapp_10_dollars_plus Dispatched when any purchase exceeds $ 10. mrgs_valid_inapp_50_dollars_plus Dispatched when any purchase exceeds $ 50. mrgs_valid_inapp_100_dollars_plus Dispatched for any purchase over $ 100. Test purchases
Since MRGS SDK
6.4.0version, test purchases will be sent to Firebase butvalueof such purchases will be0.
Getting application instance id🔗
To get the application id use the method:
Created: 2020-01-20