Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
First, obtain AppKey and download SDK
Ameng official website address
Enter the advertisement registration/login account, create App [Enter the workbench] – > Product in the upper right corner – > select [Mobile Statistics U-APP] to enter the following interface, and then add App information according to the steps. AppKey can be obtained after registration. (for example: 59892F08310C9307b60023D0)
Download the SDK official website
Click the portal above or download it from the homepage – Developer Center – SDK; Select Unity3D check the game statistics SDK and click below to download.
Decompress the downloaded SDK ZIP package as shown in the following figure: – Basic service package: common.unitypackage – Statistics package: umengGameAnalytics_v3.2. unitypackage
2, import unitypackage, check the contents of the directory
Import two Unitypackages into the Unity project as follows:
- UmengAllinOneDemo: test other SDK, delete directly
- UmengExample: Statistics Demo open scenario and add to Build Setting
Buildpostprocessor. cs:
Due to outdated API, 34 lines are deleted and 35 lines are changed to:
Third, check the SDK code logic
Just add some comments to the calling code in the sample project and call the methods that need to be modified in your own project.
using UnityEngine;
using Umeng; // Introduce the fraternal namespace
using System.Collections.Generic;
public class UmengGameExample : MonoBehaviour
{
void Start()
{
// Start the initialization of the alliance.
// Parameter: Umeng appKey, channel name
GA.StartWithAppKeyAndChannelId("59892f08310c9307b60023d0"."umeng");
// Set whether to print SDK information.
GA.SetLogEnabled(Debug.isDebugBuild);
}
void OnGUI()
{
int x = 150;
int y = 50;
int w = 500;
int h = 100;
int d = 150;
// Enter the game level
if (GUI.Button(new Rect(x, y, w, h), "StartLevel1"))
{
GA.StartLevel("level1");
}
y += d;
// Complete the game level
if (GUI.Button(new Rect(x, y, w, h), "FinishLevel"))
{
GA.FinishLevel("level1");
}
// There is also an unfinished game level
// GA.FailLevel("level1");
y += d;
// Players get bonus statistics
if (GUI.Button(new Rect(x, y, w, h), "Bonus"))
{
GA.Bonus(10, GA.BonusSource.Source10);
}
y += d;
// Player payment statistics
if (GUI.Button(new Rect(x, y, w, h), "Pay"))
{
GA.Pay(19, GA.PaySource.Source10, 10);
}
y += d;
// Base events
if (GUI.Button(new Rect(x, y, w, h), "Event"))
{
GA.Event("EventTest");
}
y += d;
// Different tags will be counted separately to facilitate the comparison of different tags of the same event. If it is nil or an empty string, the background will generate a tag with the same name as eventId.
if (GUI.Button(new Rect(x, y, w, h), "EventLabel"))
{
GA.Event("event1"."label");
}
y += d;
// Attribute event
if (GUI.Button(new Rect(x, y, w, h), "EventDict"))
{
var dict = new Dictionary<string.string> (); dict.Add("Level1"."1");
GA.Event("EventDict", dict); }}}Copy the code
You need to add the corresponding event ID in the background for user-defined events. If the event ID is not added, it will be displayed on the unregistered event TAB page:
Before using it, please add the corresponding event ID in Settings > Edit Custom Event in the umeng App management background, and then pass the corresponding event ID into the project
EventId and Attributes cannot contain Spaces or special characters for keys and values. The length cannot exceed 255 characters (otherwise, the first 255 characters will be truncated). Id, ts, and du are reserved fields and cannot be used as eventId and key names
Fourth, export Xcode package tests
Add UmengExample to Build Setting, register and set the version number, and prepare to package Xcode;
Add the dependency library manually in Xcode after the export is required.
- TARGETS — >Build Phases — >Link Binary With Libraries — > + — >libz.tdb
- TARGETS — >Build Phases — >Link Binary With Libraries — > + — >libsqlite3.tbd
Add it automatically with the package editor buildPostProcessor. cs:
So just change the Team in Xcode and you can package the tests directly.
So far, the integration is complete, summary:
- Apply for AppKey and download SDK
- Create project import unitypackage
- View code modification error
- Packaging test
Five, the background view data
Real-time data page: after the game runs, if there is an increase of new users in the background, it proves that it has been successfully involved.Custom events on the statistics page (no refresh after 5 minutes or so for the first time, no refresh after 10 minutes or so)
Example above: source link
Official documentation link:
- Unity Integration Documentation
- FAQ Summary