The device unique code GAID and IDFA in Unity are used for advertising tracking and data statistics

Currently, the device can be uniquely identified, and the ID used for data collection and statistics of the program

ANDROID:

foreign:

GAID: Advertising id, namely Google Advertising ID (GAID), is a resettable unique advertising id provided to users by Google Play service, and is usually used as a unique device identifier for data collection. However, the id must be obtained only when the google play service is installed on the user's mobile phone and the network can access google. (The advertising id is also known as AAID - Android Advertising ID). Since it can be reset, it is a non-permanent identifier .

PS: The "reset" here refers to resetting the GAID of the Google service in the "Settings" of the Android system, and a new GAID will be generated after the reset. Reinstalling an application after uninstallation will not change the GAID value , and the GAID will be reset only after performing the specified operation in the system settings. The role of GAID is to track user preferences, and then push advertisements related to preferences. Turning on or off the service will not reduce the number of advertisements , but the advertisements pushed after it is turned off are randomly selected, rather than advertisements that push relevant content based on user preferences.

Reset GAID:  "Setting" -> "Ads"

    

How to get the GAID of the device?

There are two ways:

One is to query directly in the mobile phone settings "Setting -> Ads", as shown in the figure above.

However, there is no Google service for the domestic Android system. After reinstalling the Google three-piece set, you still cannot find the "Google" or "Ads" option in the system settings. At this time, you cannot directly obtain the GAID from the phone settings. You need to use third-party software to view it. Here we recommend the "AAID" of the google play store:

The second is obtained through code:

 1. Obtain the GAID and ad tracking status of the current device:

string GetAdvertisingId()
{
	string advertisingId = "DEFAULT";

	AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
	AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");

	AndroidJavaClass jc2 = new AndroidJavaClass("com.google.android.gms.ads.identifier.AdvertisingIdClient");
	AndroidJavaObject jo2 = jc2.CallStatic<AndroidJavaObject>("getAdvertisingIdInfo", jo);
	if (jo2 != null)
	{
		//获取广告id:
		advertisingId = jo2.Call<string>("getId");
		if (string.IsNullOrEmpty(advertisingId))
			advertisingId = "none";

		//获取广告跟踪状态:当为false时,则无法根据用户行为定向推送广告,但看到的广告数量并不会减少
		adTrackLimited = jo2.Call<bool>("isLimitAdTrackingEnabled");
	}

	return advertisingId;
}

The result of the operation is as follows:

PS: "isLimitAdTrackingEnabled": Whether to limit the tracking of user behavior in order to serve corresponding advertisements. When it is false, advertisements cannot be served according to user behavior, but the number of advertisements seen will not decrease. The default is false, which means that user behavior can be tracked

Notice:

1. If you just want to get the GAID of the Android device, you don't need to import any other plug-ins, just add in the dependency of mainTemplate.gradle after custom: implementation 'com.google.android.gms:play-services-ads -identifier:18.0.1' is enough

Actual project test: use Unity2018.4.1f1 to create a new empty project, and then check "Custom Gradle Template" in Player Setting -> Publishing Setting:

Add the implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1' to the newly generated file "mainTemplate.gradle" to successfully call the method of obtaining GAID. Project source code: Get Android Device Ads id——GAID-Unity3D Document Resource-CSDN Download

2. The java class "com.google.android.gms.ads.identifier.AdvertisingIdClient" used in the C# method is in "com.google.android.gms:play-services-ads-identifier", not "com .google.android.gms:play-services-ads", so don't fill in the wrong dependencies.

Information and dependencies related to each Google can be found in the official Guide: https://developers.google.com/android/guides/setup

2. Check whether Google Play service is available on the current device?

//该方法已验证,可以正常得到返回结果,用于获取当前设备的google play服务状态

int CheckGooglePlayServiceAvailable()
{
	AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
	AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");

	AndroidJavaClass jc2 = new AndroidJavaClass("com.google.android.gms.common.GoogleApiAvailability");
	AndroidJavaObject jo2 = jc2.CallStatic<AndroidJavaObject>("getInstance");

	int code = jo2.Call<int>("isGooglePlayServicesAvailable", jo);
	return code;

	// result codes from https://developers.google.com/android/reference/com/google/android/gms/common/ConnectionResult

	// 0 == success
	// 1 == service_missing
	// 2 == update service required
	// 3 == service disabled
	// 18 == service updating
	// 9 == service invalid
}

Note: The java class used in the above method: "com.google.android.gms.common.GoogleApiAvailability" needs to import the Google Play Games plug-in into the project before it can be called normally.

https://github.com/playgameservices/play-games-plugin-for-unity

Project measurement: Unity2018.4.1f1, GooglePlayGamesPlugin-0.10.14.unitypackage

operation result:

 Project source code: Get the googleplayservice status and GAID of Android devices, and ad tracking-Unity3D Documentation Resources-CSDN Download

domestic:

1. IMEI: It can uniquely identify a device and cannot be reset. It is the code for the operator to identify the information of the device connected to the network. Every IMEI in the world is different. Since it cannot be reset, it is a permanent identifier.

Due to the uniqueness and stability of IMEI, IMEI is currently widely used in China. However, with the upgrade of the Android version, after Android 10, due to Google's strengthening of privacy protection, Android Q can no longer obtain the IMEI code of the device.

2. OAID: In view of the special environment in China, GAID cannot be used, and with the popularization of Android 10, IMEI can no longer be obtained, so the OAID——Open Anonymous Device Identifier developed by China Mobile Security Alliance recently, has a stable and uniqueness, which can be used to uniquely identify the device. And the ID can also be used for advertising tracking and can be reset, so it is usually used to replace the foreign GAID to achieve the same effect. However, it has not been gradually used until after Android 10. The picture below shows the current domestic terminals that support OAID:

IOS:

Correspondingly, on IOS devices, the advertising id is "IDFA", that is, Identifier For Advertising, which is the unique advertising id set by ios for each user. Since IOS devices can be used normally at home and abroad, all IOS devices use IDFA as a unique identifier.

Unity provides methods for obtaining Advertising ID for IOS:

//该方法当前尚没有在IOS设备上得到直接验证
Application.RequestAdvertisingIdentifierAsync(
            (string advertisingId, bool trackingEnabled, string error) =>
            { Debug.Log("advertisingId " + advertisingId + " " + trackingEnabled + " " + error); }
        );

Note: ATT window - In order to enhance user privacy, IOS14 introduces the ATT window: If user data is collected for tracking purposes, user authorization must be obtained before the IDFA of the IOS device can be obtained, otherwise the IDFA data obtained by the application will be empty.

PS:

1. Report an error after importing the GoogleMobileAds​​​​​​​​plug-in ( this project does not need to import the plug-in, the reason why this problem is encountered is because it happens to be encountered during development, so record it ):

When importing the Unity plugin of Google Ads, the latest version will be used by default - GoogleMobileAds-v7.0.0.unitypackage. However, for earlier versions of Unity such as Unity2018.4.1f1, it does not support the dependency on Timeline in the package, so Unity2018.4.1f1 will report an error after importing the latest version of "GoogleMobileAds-v7.0.0.unitypackage":

Solution: Update the Unity version, such as Unity2019; or download an earlier version of GoogleMobileAds, such as

After testing, after importing "GoogleMobileAds-v3.18.3.unitypackage" in Unity2018.4.1f1, there is no error reported as above

2. Failed to resolve dependencies: When manually resolving dependencies, there is no response after clicking "Resolve"

 This may be because: when the GoogleMobileAds-v3.18.3.unitypackage plug-in is imported for the first time, Unity will automatically resolve the dependencies, but due to the long time, the window showing the progress of the resolution is artificially interrupted. Clicking "Resolve" again later does not respond. At this time, check "mainTemplate.gradle" and find that there is no change, and the dependencies have not been added, indicating that the resolution of the dependencies has not been successful.

Solution: Click "Delete Resolved Libraries" in the screenshot, then close and reopen the project , and click "Resolve" again to restart parsing dependencies. If the following window pops up, it means that the dependency analysis is successful

Guess you like

Origin blog.csdn.net/m0_47975736/article/details/123482768