Skip to content

Getting started with MRGSMyTracker🔗

MyTracker - SDK for collecting statistics, read more on the official website. MRGS allows you to automatically start the sdk and pass most of the necessary events to it and much more.

MyTracker is only supported for mobile platforms.

To integrate, you need to follow a few simple steps:

Step 1. Import MRGSMyTracker module🔗

Adding to Unity 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 scopedRegistries section to the Packages/manifest.json file 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 package MRGSMyTracker from 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 the games.my.mrgs.mytracker.unitypackage package from the downloaded archive.
  • (For tgz integration) In Unity, click Window -> Package Manager -> '+' -> Add package from tarball, and select the games.my.mrgs.mytracker-<version> package. tgz from the downloaded archive.
  • Import the module: using MRGS;
Adding to iOS 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 MRGSMyTracker from "MRGS Package Collection".
  • Or you can select "MRGS" package from "MRGS Package Collection" (contains all mrgs modules as products) and then select "MRGS/MyTracker" 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/mrgsmytracker-ios-sdk.git
  • Add a module to your project
  • Or you can paste the url https://mrgs-gitea.my.games/mrgs/ios-sdks.git to include the "MRGS" package which contains all mrgs modules as products and then select only the product" MRGS/MyTracker".

Step 2: Add support for ObjectiveC categories

  • Set the -ObjC flag in the "Other linker Flags" field in the project settings.
  • Import the module in code: @import MRGServiceKit; or @import MRGSMyTracker; or #import <MRGSMyTracker/MRGSMyTracker.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 repo

Step 2: Add dependencies

Add the latest version of MRGSMyTracker to target:

To add via subspecs:

target 'MyProject' do
    pod 'MRGS', '~> 5.0.0', :subspecs => ['MyTracker']
end

To add via individual modules:

target 'MyProject' do
    pod 'MRGSMyTracker', '~> 5.0.0'
end

To add all mrgs modules:

target 'MyProject' do
    pod 'MRGS/AllKits', '~> 5.0.0'
end

Step 3: Install dependencies

  • Run pod install (or pod install --repo-update if necessary)
  • Import the module in code: @import MRGServiceKit; or @import MRGSMyTracker; or #import <MRGSMyTracker/MRGSMyTracker.h>

Step 1: Add dependencies

Add the dependency to your Cartfile:

binary "https://mrgs-nexus.my.games/repository/ios-sdks/MRGSMyTracker/MRGSMyTracker.json" ~> 5.0.0

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 -ObjC flag in the "Other linker Flags" field in the project settings.
  • Import the module in code: @import MRGServiceKit; or @import MRGSMyTracker; or #import <MRGSMyTracker/MRGSMyTracker.h>
  • Download the latest version of the library. Unzip the archive.
  • Add MRGSMyTracker.xcframework from the downloaded archive to your project (Drag the libraries to the "Linked frameworks and Libraries" section) (Also contains MRGSMyTracker.framework for compatibility - fat framework)

  • Set the -ObjC flag in the "Other linker Flags" field in the project settings.

  • Import the module in code: @import MRGSMyTracker; or #import <MRGSMyTracker/MRGSMyTracker.h>
  • Also, you can add the MRGServiceKit.h and module.modulemap files from the archive to your project, or specify the path to them in the project settings in the Build Settings -> Header search paths section. Now, instead of importing each of our frameworks separately, you can only import one header file: @import MRGServiceKit;
Adding to Android project
dependencies {
    def mrgsVersion = "6.x.x"

    implementation "games.my.mrgs:mytracker:$mrgsVersion"
}

Copy the MRGSMyTracker.aar file to the libs directory of your project. Add the necessary dependencies to the build file.

dependencies {
    //...
    implementation(name: 'MRGService', ext:'aar')
    implementation(name: 'MRGSMyTracker', ext:'aar')

    implementation "com.my.tracker:mytracker-sdk:$myTrackerVersion"
}

Since version 6.0.0-a MyTracker is a separate module

Huawei/AppTouch Store

Add dependency as per documentation

dependencies {
    //... other dependencies
    implementation 'com.huawei.hms:ads-identifier:3.4.62.300'
}

Step 2. Preliminary setup and initialization🔗

When starting MRGS SDK you need to pass parameters (MY_TRACKER_SDK_KEY) and settings for MyTracker:

var modulesParams = new List<MRGSExternalSDKSettings>();
modulesParams.Add( new MRGSMyTrackerParams(AppSettings.MYTRACKER_APPKEY)
{
    Debug = true,
    ForwardMetrics = true,
    TrackingLocationEnabled = true
});

// MRGS Initialization
MRGService.Instance.Initialize(serviceParams,  modulesParams);
@import MRGService;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // MRGService settings
    MRGServiceParams *mrgsParams = [[MRGServiceParams alloc] initWithAppId: <MRGS_APP_ID> secret: <CLIENT_SECRET>];
    // MyTracker
    MRGSMyTrackerParams *myTrackerParams = [[MRGSMyTrackerParams alloc] initWithAppId: <MY_TRACKER_SDK_KEY>];
    myTrackerParams.forwardMetrics = YES; // All MRGS metrics sent through the MRGSMetrics class will automatically be sent to MyTracker
    //Start MRGS
    [MRGService startWithServiceParams:mrgsParams externalSDKParams:@[myTrackerParams] delegate:nil];
}
import java.util.ArrayList;
import java.util.List;
import games.my.mrgs.MRGSModuleParams;
import games.my.mrgs.MRGSPlatform;
import games.my.mrgs.MRGService;
import games.my.mrgs.MRGServiceParams;
import games.my.mrgs.my.tracker.MRGSMyTrackerParams;

public class YourApplicationClass extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        final MRGServiceParams serviceParams = MRGServiceParams.init(<MRGS_APP_ID>, <CLIENT_SECRET>, MRGSPlatform.ANDROID);
        serviceParams.setDebuggable(false);
        // Settings for MRGSModules
        final List<MRGSModuleParams> moduleParams = new ArrayList<>();
        // Setting MyTracker
        final MRGSMyTrackerParams myTrackerParams = MRGSMyTrackerParams.init("MY_TRACKER_SDK_KEY");
        myTrackerParams.setDebuggable(false);
        moduleParams.add(myTrackerParams);
        MRGService.service(context, serviceParams, moduleParams);
    }
}
MY_TRACKER_SDK_KEY

MY_TRACKER_SDK_KEY - SDK key of the MyTracker library. It can be obtained from the MyTracker website in the settings section of your application mytracker_settings

Important! Don't forget that this setting is different for Android and iOS builds. Use the correct initialization keys

Step 3. Login tracking🔗

For the correct calculation of game statistics (the number of registrations and authorizations, as well as LifeTime payments) in the MyTracker/1link system, it is necessary to report these events using the following methods:

// After user registration
MRGSMyTracker.Instance.TrackRegistrationEvent();
// After user authorization
MRGSMyTracker.Instance.TrackLoginEvent();
// After user registration
[MRGSMyTracker trackRegistrationEvent];

// After user authorization
[MRGSMyTracker trackLoginEvent];
import games.my.mrgs.my.tracker.MRGSMyTracker;

// After user registration
MRGSMyTracker.getInstance().trackRegistrationEvent();
// After user authorization
MRGSMyTracker.getInstance().trackLoginEvent();

Attention!

trackLoginEvent must be called in any case - whether the user was registered or authorized. The trackRegistrationEvent method should only be called when registering (creating) a user account. Both of these methods must be called after calling the MRGSUsers#setUserId method otherwise the events will be sent without a user id and the statistics will be inaccurate.

Automatic events sending🔗

MRGS will automatically call the following MyTracker methods to send the necessary events:

  • When initializing MyTracker, the customUserId parameter will be set. USER_ID will be transferred there if there is one saved from the previous session
  • After receiving deviceId, the setMrgsId method will be called with the received deviceId
  • When calling the MRGSUsers#setUserId method, the customUserId parameter of MyTracker will be set
  • When sending a metric, the trackEvent method will be called if metrics forwarding has not been disabled
  • For Unity, when the game starts, the trackLaunchManually method will be called
  • When making a payment on Android, the trackPurchaseEvent method will be called. On iOS, MyTracker subscribes to a transaction queue on its own to track payments made.

Sending events🔗

Using this API, you can send events to MyTracker directly. For instance:

var params = new Dictionary<string,string>();
params["someInfoKey"] = "someImportantInfo";

MRGSMyTracker.Instance.TrackEvent("someEvent", params);
[MRGSMyTracker trackEventWithName:@"someEvent" eventParams:@{@"level":@"1"}];
Map<String, String> params = new TreeMap<>();
params.put("androidParam", "androidValue");

MRGSMyTracker.getInstance().trackEvent("someEvent", params);

Managing sending parameters🔗

You can set the interval in seconds during which events will accumulate on the device before sending them to the server. The default interval is 900 seconds. The value can be set in the range of 1-86400 seconds (24 hours).

MRGSMyTracker.Instance.SetBufferingPeriod(1000);
[MRGSMyTracker setBufferingPeriod:1000];
MRGSMyTracker.getInstance().setBufferingPeriod(1000);

Also, you can set the interval in seconds during which events will accumulate on the device before sending them to the server. The default interval is 900 seconds. The value can be set in the range of 1-86400 seconds (24 hours).

MRGSMyTracker.Instance.SetForcingPeriod(1000);
[MRGSMyTracker setForcingPeriod:1000];
MRGSMyTracker.getInstance().setForcingPeriod(1000);

Also, you can set the interval in seconds during which a new launch is not tracked and a session is not interrupted while app is in background. Possible values range: 30-7200 seconds. 30 sec by default.

MRGSMyTracker.Instance.SetLaunchTimeout(30);
[MRGSMyTracker setLaunchTimeout:30];
MRGSMyTracker.getInstance().setLaunchTimeout(30);

To send the accumulated events immediately, use the flush method (We do not recommend calling it too often).

MRGSMyTracker.Instance.Flush();
[MRGSMyTracker flush];
MRGSMyTracker.getInstance().flush();

Getting data from MyTracker🔗

To get a unique InstanceID for S2S events sending, use the method:

 MRGSMyTracker.Instance.GetInstanceId((string instanceID) => {
    Debug.Log("MRGSMyTracker GetInstanceId: " + instanceID ?? "null");
});
[MRGSMyTracker getInstanceIdWithCompletionHandler: ^(NSString* instanceID) {
    NSLog(@"MyTracker getInstanceIdWithCompletionHandler: %@", instanceID);
}];
MRGSMyTracker.getInstance().getInstanceId(Context, new Consumer<String>() {
    @Override
    public void accept(String instanceId) {
        Log.v("MRGSMyTracker", "instanceId: " + instanceId);
    }
});

To support deeplinks and deferred deeplinks (Deeplink or Deffered deeplink), you need to install a delegate in your application (not important before or after starting MRGS) to get information about them. The delegate will be called upon the first launch of the application if a delayed diplink was found for the current installation, as well as every time the application is launched via the diplink. An attribute object MRGSMyTrackerAttribution containing the deeplink property will be passed as a parameter when called:

MRGSMyTracker.Instance.SetAttributionListener((MRGSMyTrackerAttribution attribution) => {
    Debug.Log("Received attribution from MRGSMyTracker - " + attribution.Deeplink);
});
// Setting the delegate:
// Where self is an object that implements the MRGSMyTrackerAttributionDelegate protocol
[MRGSMyTracker setAttributionDelegate: self];

// Implementation of the delegate:
- (void)didReceiveAttribution:(nonnull MRGSMyTrackerAttribution *)attribution {
    NSLog(@"MRGSMyTracker didReceiveAttribution delegate called with data - %@", attribution.deeplink);
}
// Where this is an object that implements the MRGSMyTrackerAttributionListener interface
MRGSMyTracker.getInstance().setAttributionsListener(this)

// Implementation of the delegate:
void onDeepLink(String deepLink) {
    //deepLink will contain attribution data
}

DeepLinks allow you to pass additional parameters to it when you start the application. These options can be used to go to a specific application screen. Deferred deeplinks allow you to transfer additional parameters to the application at the first start after installation. These parameters can be used in the same way as in the case of conventional DeepLink.

To set up delayed deeplinks from MyTracker, refer to the MyTracker documentation.

Manage event tracking from MRGSMetrics🔗

By default, MRGSMetrics duplicates events in MyTracker. If for some reason you need to disable sending, just add the setting in setup:

var trackerParams = // ...

trackerParams.ForwardMetrics = false;

// MRGS Initialization
...
myTrackerParams.forwardMetrics = NO;

[MRGService startWithServiceParams:<params> externalSDKParams:externalParams delegate:nil];
...
myTrackerParams.setForwardMetricsEnabled(false);

// MRGS Initialization

Setting customerUserID🔗

If you want to set your own userId, you need to call the specified method before initializing MRGS, passing null there (then we will not put any data in this field at the start of the sdk), and after you have the userId, set it through the specified method. Also, you can immediately set your userId before the start of MRGS.

MRGSMyTracker.Instance.ForceCustomUserId("your_customer_user_id");
[MRGSMyTracker forceCustomUserId:@"your_customer_user_id"];
MRGSMyTracker.forceCustomUserId("your_customer_user_id")

Tracking location🔗

MRGS disables user location tracking in MyTracker by default, if for some reason you need to change this behavior, then just add the setting in setup:

var trackerParams = // ...

trackerParams.TrackingLocationEnabled = false;

// MRGS Initialization
serviceParams.locationTrackingEnabled = YES;

[MRGService startWithServiceParams:serviceParams];
myTrackerParams.setTrackingLocationEnabled(true);

// MRGS Initialization

Last update: 2023-10-25
Created: 2020-01-20