Getting the Google Advertising ID and Limit Advertising
Asked Answered
B

1

3

I'm building a Unity Android app, and looking at some advertising. One of the services we are considering requires my google advertising ID and limit advertising state in order to do server-to-server conversion tracking.

The problem is I'm not sure how to get either of these values within Unity. It seems like I would need some form of plugin? I already have google ad services implemented and in use for both AdMob and Chartboost, but as near as I can tell neither of these plugins give me access to the java calls I would need to retrieve the aforementioned values.

So I guess I'm not sure how to access the data I need. I'm hesitant to add more plugins to the game because they are getting difficult enough to manage as it is. If I understand correctly I think there should be a way to access the java through Unity's libraries, but I haven't the slightest how to do that.

Benne answered 27/1, 2015 at 20:14 Comment(2)
You did not ask a (specific) question. Note that asking for recommendations is offtopic here, if that's what it boils down to.Zaller
Right, sorry. I've added some clarification.Benne
B
6

I was able to get the desired data using the following code:

string advertisingID = "";
bool limitAdvertising = false;

AndroidJavaClass up = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject> ("currentActivity");
AndroidJavaClass client = new AndroidJavaClass ("com.google.android.gms.ads.identifier.AdvertisingIdClient");
AndroidJavaObject adInfo = client.CallStatic<AndroidJavaObject> ("getAdvertisingIdInfo",currentActivity);

advertisingID = adInfo.Call<string> ("getId").ToString();   
limitTracking = (adInfo.Call<bool> ("isLimitAdTrackingEnabled"));
Benne answered 2/2, 2015 at 16:10 Comment(1)
You will recevie: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.identifier.AdvertisingIdClient" If using that method.Fervor

© 2022 - 2025 — McMap. All rights reserved.