Skip to content

Commit 1733ad2

Browse files
authored
Update README.en.md
1 parent 0caee86 commit 1733ad2

File tree

1 file changed

+5
-344
lines changed

1 file changed

+5
-344
lines changed

README.en.md

+5-344
Original file line numberDiff line numberDiff line change
@@ -1,349 +1,10 @@
1-
## MetrixSDK Unity Doc
1+
## MetrixSDK Unity Sample
22

3-
4-
*Read this in other languages: [فارسی](README.md) , [English](README.en.md).*
5-
6-
<h2>Table of contents</h2>
7-
<a href=#project_setup>1. Basic integration</a><br>
8-
<a href=#install_referrer>2. install referrer</a><br>
9-
<a href=#google_play_store_intent>2.1. google play store intent</a><br>
10-
<a href=#integration>3. Add the SDK to your project</a><br>
11-
<a style="padding-left:2em" href=#application_setup>3.1. Initial configuration in the app</a><br>
12-
<a href=#methods>4. Additional features</a><br>
13-
<a style="padding-left:2em" href=#session_event_description>4.1. Explain the concepts of event and session</a><br>
14-
<a style="padding-left:2em" href=#enableLocationListening>4.2. Enable location listening</a><br>
15-
<a style="padding-left:2em" href=#setEventUploadThreshold>4.3. Limitation in number of events to upload</a><br>
16-
<a style="padding-left:2em" href=#setEventUploadMaxBatchSize>4.4. Limitation in number of events to send per request</a><br>
17-
<a style="padding-left:2em" href=#setEventMaxCount>4.5. Limitation in number of events to buffer on the device</a><br>
18-
<a style="padding-left:2em" href=#setEventUploadPeriodMillis>4.6. The time interval for sending events</a><br>
19-
<a style="padding-left:2em" href=#setSessionTimeoutMillis>4.7. The session timeout</a><br>
20-
<a style="padding-left:2em" href=#enableLogging>4.8. Log management</a><br>
21-
<a style="padding-left:2em" href=#setLogLevel>4.9. Set LogLevel</a><br>
22-
<a style="padding-left:2em" href=#setFlushEventsOnClose>4.10. Flush all events</a><br>
23-
<a style="padding-left:2em" href=#getSessionNum>4.11. Current session number</a><br>
24-
<a style="padding-left:2em" href=#newEvent>4.12. Custom event</a><br>
25-
<a style="padding-right:2em" href=#newRevenue>4.13. Track Revenue</a><br>
26-
<a style="padding-left:2em" href=#setScreenFlowsAutoFill>4.14. Enable the process of storing the user flow</a><br>
27-
<a style="padding-left:2em" href=#setDefaultTracker>4.15. Pre-installed trackers</a><br>
28-
29-
30-
31-
<h2 id=project_setup>Basic integration</h2>
32-
33-
1. Download the latest version from [our releases page](https://storage.backtory.com/metricx/sdk-unity/MetrixSDK-v0.9.1.unitypackage).
34-
Open your project in the Unity Editor and navigate to Assets → Import Package → Custom Package and select the downloaded Unity package file.
35-
36-
2. Add the following libraries to the `dependencies` section of your `Asset/Plugins/Android/mainTemplate.gradle` file:
37-
<div dir="ltr">
38-
39-
implementation fileTree(dir: 'libs', include: [‘*.jar'])
3+
This is the Unity SDK of Metrix. You can read more about Metrix at [metrix.ir](https://metrix.ir).
404

41-
implementation 'com.android.installreferrer:installreferrer:1.0'
5+
Read this in other languages: [فارسی](README.md) , [English](README.en.md).
426

43-
implementation 'com.google.code.gson:gson:2.8.5'
7+
## Installation
8+
See Metrix [Unity sdk installation](https://metrix.ir/docs/en/sdk/unity) document.
449

45-
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
4610

47-
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
48-
49-
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
50-
51-
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
52-
53-
implementation 'com.google.android.gms:play-services-analytics:16.0.7'
54-
55-
</div>
56-
57-
3. Add the following options to the `android` block of your application's `Asset/Plugins/Android/mainTemplate.gradle` file:
58-
59-
<div dir="ltr">
60-
61-
compileOptions {
62-
targetCompatibility = "8"
63-
sourceCompatibility = "8"
64-
}
65-
</div>
66-
67-
68-
4. If you are using Proguard, add these lines to your `Proguard` file:
69-
70-
<div dir=ltr>
71-
72-
#Unity Player
73-
-keep class com.unity3d.player.** { *; }
74-
75-
-keepattributes Signature
76-
-keepattributes *Annotation*
77-
-keepattributes EnclosingMethod
78-
-keepattributes InnerClasses
79-
80-
-keepclassmembers enum * { *; }
81-
-keep class **.R$* { *; }
82-
-keep interface ir.metrix.sdk.NoProguard
83-
-keep class * implements ir.metrix.sdk.NoProguard { *; }
84-
-keep interface * extends ir.metrix.sdk.NoProguard { *; }
85-
-keep class ir.metrix.sdk.network.model.** { *; }
86-
87-
# retrofit
88-
# Retain service method parameters when optimizing.
89-
-keepclassmembers,allowshrinking,allowobfuscation interface * {
90-
@retrofit2.http.* <methods>;
91-
}
92-
93-
# Ignore JSR 305 annotations for embedding nullability information.
94-
-dontwarn javax.annotation.**
95-
96-
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
97-
-dontwarn kotlin.Unit
98-
99-
# Top-level functions that can only be used by Kotlin.
100-
-dontwarn retrofit2.-KotlinExtensions
101-
102-
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
103-
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
104-
-if interface * { @retrofit2.http.* <methods>; }
105-
-keep,allowobfuscation interface <1>
106-
107-
#OkHttp
108-
# A resource is loaded with a relative path so the package of this class must be preserved.
109-
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
110-
111-
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
112-
-dontwarn org.codehaus.mojo.animal_sniffer.*
113-
114-
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
115-
-dontwarn okhttp3.internal.platform.ConscryptPlatform
116-
117-
118-
119-
#Gson
120-
# Gson specific classes
121-
-dontwarn sun.misc.**
122-
#-keep class com.google.gson.stream.** { *; }
123-
124-
# Prevent proguard from stripping interface information from TypeAdapterFactory,
125-
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
126-
-keep class * implements com.google.gson.TypeAdapterFactory
127-
-keep class * implements com.google.gson.JsonSerializer
128-
-keep class * implements com.google.gson.JsonDeserializer
129-
130-
#referral
131-
-keep public class com.android.installreferrer.** { *; }
132-
133-
#gms
134-
-keep class com.google.android.gms.** { *; }
135-
-dontwarn android.content.pm.PackageInfo
136-
137-
</div>
138-
139-
5. Please add the following permissions, which the Metrix SDK needs, if they are not already present in your `AndroidManifest.xml` file in `Plugins/Android` folder:
140-
141-
<div dir=ltr>
142-
143-
<uses-permission android:name="android.permission.INTERNET" />
144-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
145-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!--optional-->
146-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!--optional-->
147-
</div>
148-
149-
(Two last permissions are optional)
150-
151-
<h2 id=install_referrer>Install Referrer</h2>
152-
153-
In order to correctly attribute an install of your app to its source, Metrix needs information about the **install referrer**. This can be obtained by using the **Google Play Referrer API** or by catching the **Google Play Store intent** with a broadcast receiver.
154-
155-
**Important**: The Google Play Referrer API is newly introduced by Google with the express purpose of providing a more reliable and secure way of obtaining install referrer information and to aid attribution providers in the fight against click injection. It is **strongly advised** that you support this in your application. The Google Play Store intent is a less secure way of obtaining install referrer information. It will continue to exist in parallel with the new Google Play Referrer API temporarily, but it is set to be deprecated in future.
156-
157-
158-
<h3 id=google_play_store_intent>Google Play Store intent</h3>
159-
160-
The Google Play Store `INSTALL_REFERRER` intent should be captured with a broadcast receiver. If you are **not using your own broadcast receiver** to receive the `INSTALL_REFERRER` intent, add the following `receiver` tag inside the `application` tag in your `AndroidManifest.xml`.
161-
162-
```
163-
<receiver
164-
android:name="ir.metrix.sdk.MetrixReferrerReceiver"
165-
android:permission="android.permission.INSTALL_PACKAGES"
166-
android:exported="true" >
167-
<intent-filter>
168-
<action android:name="com.android.vending.INSTALL_REFERRER" />
169-
</intent-filter>
170-
</receiver>
171-
```
172-
173-
<h2 id=integration>Implement the SDK in your project</h2>
174-
175-
<h3 id=application_setup>Initial configuration in the app</h3>
176-
177-
You need to initialize the Metrix SDK in `onCreate` method of your `Application`. If you do not already have a class `Application` in your project, create this class as below:<br>
178-
Initialize Metrix according to the code below: <br>
179-
180-
<div dir=ltr>
181-
182-
Metrix.Initialize("APP_ID");
183-
</div>
184-
185-
186-
Replace `APP_ID` with your application id. You can find that in your Metrix's dashboard.
187-
188-
<h2 id=methods>Additional features</h2>
189-
190-
<h3 id=session_event_description>Events and sessions</h3>
191-
In each interaction that the user has with the app, Metrix sends this interaction to the server as an <b>event</b>. In Metrix, a <b>session</b> is a specific timeframe during which the user interacted with the app.<br>
192-
There are three types of events in Metrix:<br>
193-
<b>1. Session Start:</b> The time a session starts.<br>
194-
<b>2. Session Stop:</b> The time of a session ends.<br>
195-
<b>3. Custom:</b> Depending on your application logic and the interactiion that the user has with your app, you can create and send custom events as below:<br>
196-
197-
198-
<h3 id=enableLocationListening>Enable location listening</h3>
199-
Using the following functions, you can inform Metrix that you wish to send information about the location of the user (In order for these methods to work properly, the optional permissions explained earlier must be enabled). <br>
200-
<div dir=ltr>
201-
202-
Metrix.EnableLocationListening();
203-
204-
Metrix.DisableLocationListening();
205-
</div>
206-
207-
<h3 id=setEventUploadThreshold>Limitation in number of events to upload</h3>
208-
Using the following function, you can specify that each time the number of your buffered events reaches the threshold, the Metrix SDK should send them to the server:<div dir=ltr>
209-
210-
Metrix.SetEventUploadThreshold(50);
211-
</div>
212-
(The default value is 30 events.)<br>
213-
214-
<h3 id=setEventUploadMaxBatchSize>Limitation in number of events to send per request</h3>
215-
Using this function, you can specify the maximum number of out-going events per request as shown below:<br>
216-
<div dir=ltr>
217-
218-
Metrix.SetEventUploadMaxBatchSize(100);
219-
</div>
220-
(The default value is 100 events.)<br>
221-
222-
<h3 id=setEventMaxCount>Limitation in number of events to buffer on the device</h3>
223-
Using the following function, you can specify the maximum number of events that are buffered in the SDK (for example, if the user's device loses internet connection, the events will be buffered in the library until there is a chance to send the events and empty the buffer) and if the number of buffered events in the library passes this amount, old events are destroyed by SDK to make space for new events:<br>
224-
<div dir=ltr>
225-
226-
Metrix.SetEventMaxCount(1000);
227-
</div>
228-
(The default value is 100 events.)<br>
229-
230-
<h3 id=setEventUploadPeriodMillis>The time interval for sending events</h3>
231-
By using this function, you can specify the timeout period of requests for sending events: <br>
232-
<div dir=ltr>
233-
234-
Metrix.SetEventUploadPeriodMillis(30000);
235-
</div>
236-
(The default value is 30 seconds.)<br>
237-
238-
<h3 id=setSessionTimeoutMillis>The session timeout</h3>
239-
Using this function, you can specify the limit of session length in your application in unit of miliseconds. For example, if this value is 10,000 and the user interacts with the application for 70 seconds, Metrix calculates this interaction as seven sessions.<br>
240-
<div dir=ltr>
241-
242-
Metrix.SetSessionTimeoutMillis(1800000);
243-
</div>
244-
(The default value is 30 minutes.)<br>
245-
246-
<h3 id=enableLogging>Log management</h3>
247-
Note that you should set this value to `false` before the release of your application:<br>
248-
<div dir=ltr>
249-
250-
Metrix.EnableLogging(true);
251-
</div>
252-
(The default value is true.)<br>
253-
254-
<h3 id=setLogLevel>Set LogLevel</h3>
255-
256-
Using this function, you can specify what level of logs to be printed in `logcat`, for example, the following command will display all logs except `VERBOSE` in `logcat`:<br>
257-
<div dir=ltr>
258-
259-
Metrix.SetLogLevel(3);
260-
</div>
261-
262-
(The default value is `Log.INFO`.)<br>
263-
264-
The value of `Log Level` can be one of the following:
265-
266-
<div dir=ltr>
267-
268-
VERBOSE = 2;
269-
DEBUG = 3;
270-
INFO = 4;
271-
WARN = 5;
272-
ERROR = 6;
273-
ASSERT = 7;
274-
275-
</div>
276-
277-
<h3 id=setFlushEventsOnClose>Flush all events</h3>
278-
Using this function, you can specify whether when the application is closed, all events buffered in the device, should be sent or not:
279-
<br>
280-
<div dir=ltr>
281-
282-
Metrix.SetFlushEventsOnClose(false);
283-
</div>
284-
(The default value is true.)<br>
285-
286-
<h3 id=getSessionNum>Current session number</h3>
287-
By this function, you can find the current session number:<br>
288-
<div dir=ltr>
289-
290-
Metrix.GetSessionNum();
291-
</div>
292-
293-
<h3 id=newEvent>Custom event</h3>
294-
295-
You can use Metrix to track any event in your app. Suppose you want to track every tap on a button. You would have to create a new event slug in the Events Management section of your dashboard. Let's say that event slug is `abc123`. In your button's onClick method you could then add the following lines to track the click.
296-
<br>
297-
You can call this function in this way:<br>
298-
Make a custom event that has only one specified name:<br>
299-
300-
<div dir=ltr>
301-
302-
Metrix.NewEvent(“abc123");
303-
</div>
304-
305-
The input of this function is String.<br>
306-
<br>
307-
308-
309-
<h3 id=newRevenue>Track Revenue</h3>
310-
311-
If your users can generate revenue by tapping on advertisements or making in-app purchases, you can track those revenues too with events. You can also add an optional order ID to avoid tracking duplicate revenues. By doing so, the last ten order IDs will be remembered and revenue events with duplicate order IDs are skipped. This is especially useful for tracking in-app purchases. You can see an example below where a tap is worth 12,000 IRR:
312-
313-
<div dir=ltr>
314-
315-
Metrix.NewRevenue("my_event_slug", 12000, 0, "2");
316-
</div>
317-
The first parameter is the slug you get from the dashboard. <br>
318-
The second parameter is the amount of revenue. <br>
319-
The third parameter is the currency of this event. If you do not set the value, Rial is be considered as default value. You can see below its values: <br>
320-
321-
1- `0` Rial
322-
323-
2- `1` Dollars
324-
325-
3- `2` Euro
326-
327-
The fourth parameter is your order number. <br>
328-
<br>
329-
330-
331-
<h3 id=setScreenFlowsAutoFill>Enable the process of storing the user flow</h3>
332-
333-
Using this function, you can inform the Metrix to gather information about user's flow in each `Activity`/`Fragment` and these details should be stored automatically:<br>
334-
<div dir=ltr>
335-
336-
Metrix.ScreenDisplayed("First Screen");
337-
</div>
338-
339-
340-
<h3 id=setDefaultTracker>Pre-installed trackers</h3>
341-
342-
If you want to use the Metrix SDK to recognize users whose devices came with your app pre-installed, open your app delegate and set the default tracker of your config. Replace `trackerToken` with the tracker token you created in dashboard. Please note that the Dashboard displays a tracker URL (including http://tracker.metrix.ir/). In your source code, you should specify only the six-character token and not the entire URL. <br>
343-
<div dir=ltr>
344-
345-
Metrix.SetDefaultTracker("trackerToken");
346-
</div>
347-
348-
349-
</div>

0 commit comments

Comments
 (0)