9

I have added to WMAppManifest.xml:

  • <Capability Name="ID_CAP_IDENTITY_DEVICE" />
  • <Capability Name="ID_CAP_IDENTITY_USER" />

So why do I keep getting empty strings from:

        public static string GetWindowsLiveAnonymousID()
        {
            int ANIDLength = 32;
            int ANIDOffset = 2;

            string result = string.Empty;
            object anid;
            if (UserExtendedProperties.TryGetValue("ANID", out anid))
            {
                if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
                {
                    result = anid.ToString().Substring(ANIDOffset, ANIDLength);
                }
            }

            return result;
        }

It does not seem to handle that TryGetValue very well... Someone got a clue?

Jason94
  • 13,320
  • 37
  • 106
  • 184
  • Are you sure the problem comes from the `TryGetValue`? It could be the next `if` as well. Have you tried setting a breakpoint to understand which line doesn't work? – Kevin Gosse Dec 20 '12 at 13:11
  • 2
    @KooKiz TryGetValue returns false and anid object is null :-/ – Jason94 Dec 20 '12 at 13:14

3 Answers3

15

It's called ANID2 in Windows Phone 8.

The UserExtendedProperties API exposes two properties: ANID and ANID2.

  • ANID can only be accessed from Windows Phone OS 7.0 and Windows Phone OS 7.1 apps that use the Microsoft Advertising SDK for Windows Phone.

  • ANID2 can only be accessed from Windows Phone 8 apps.

Community
  • 1
  • 1
robertk
  • 2,461
  • 1
  • 27
  • 39
  • I can confirm this behaviour: ANID2 is returning null, when I try to retrieve it. I would have thought this Anonymous ID belongs to the Windows Live account on the device which is used to access and buy apps in the store. Or is this Anonymous ID an ID which can only be retrieved if the app was signed and submitted to the Store? – Markus Rudel Feb 13 '13 at 13:51
  • @MarkusRudel, found this info in an [MSDN thread](http://social.msdn.microsoft.com/forums/windowsapps/en-US/7e265aed-1719-4158-bc98-5d985e694c4c/userextendedproperties-anid-anid2-changes-in-wp8?prof=required): `The biggest difference (between ANID and ANID2 on WP7 vs WP8) is probably that ANID2 is unique to each publisher. [...] For Windows Phone 8 projects you can set PublisherID in the WMAppManifest.xml file. You can find your PublisherID (Publisher GUID) in your Account Summary page of the Dev Center Dashboard. The PublisherID for an application is set when submitted to Dev Center [...]` – Vinney Kelly Aug 15 '14 at 22:56
1

use instead for Win Phone 8 apps

string anid = UserExtendedProperties.GetValue("ANID2") as string;

Also make sure those are checked from the WMAppManifest

<Capability Name="ID_CAP_IDENTITY_DEVICE" />
<Capability Name="ID_CAP_IDENTITY_USER" />
Mnhy
  • 49
  • 1
  • 5
0

I seem to remember you can no longer request the ANID on windows phone 8 devices as per security reasons. Same way you cant request MAC adress on W8 devices anymore. Store Guid.NewGuid() locally and identify that way.

Michiel
  • 468
  • 3
  • 23