2

I have NFC tags that should access a certain app on my phone when touched. So I put an Android Application Record on the tag for my com.example.app. Then if a user does not have the app, they get directed to the google play store where it can be downloaded.

However, I want to be able to track which nfc tag the user used. So I want to use tracking parameters like ideally it would be com.example.app/?id=1 for example. but I don't think you can do that to packages in java, and I don't think the google-analytics tracking would register that, or would it?

Perhaps there is code somewhere on the android system that, if it sees a package that it doesn't have, goes to the google play store with a generated url? Where could I find this? Perhaps I could edit this script directly?

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
BigBoy1337
  • 4,735
  • 16
  • 70
  • 138

2 Answers2

2
  • you have to use your app package name as-is when creating Android Application Record (AAR).

  • When an android device scans your NFC tag, it will look for all AAR's in NDEF, and if no matching package is currently installed, it will hand of the intent to play store (for the first AAR). I do not believe we can modify "play store" handling code.

  • But there is work around solution - if you want to use play-store and google analytics to track if your nfc tag has been used, may be you can consider creating simple proxy/tacking dummy app (may be mycom.nfc.tracking package name), and have this package AAR as the first one in your NDEF. Your real app package name AAR next.

    • This simple tracking app can have just one activity, and when invoked via nfc, it will read additional analytics ids you placed inside NDEF for tracking purpose, and update google analytics or any other analytics service you use, and then it will kick off your "real app" if installed or hand off to play store for installing real app.

    • This proxy activity can be with out any UI, so the user would not notice any of this. Its transparent, and gives you lot more flexibility in any other nfc related book-keeping/analysis.

    • If this proxy/tracking app is not already installed on device, NFC will handoff to playstore and you can use google analytics to track your nfc tag usage. This should not affect non-nfc user of your real app.

  • Note, AAR matching may be skipped entirely if there is an app already with foreground dispatch feature

ashoke
  • 6,441
  • 2
  • 26
  • 25
  • cool. are you saying that if I use the foreground dispatch feature, this is all unnecessary? If so, can you elaborate on how this feature might be used like so? – BigBoy1337 Oct 09 '14 at 21:35
  • to use `foreground dispatch` your app should have already been installed – ashoke Oct 09 '14 at 21:51
  • if the app hasn't been installed, and the dummy app hasn't been installed, then the user would be directed to the play store download page of the dummy app right? Or would it open the play store download page of the real app? How is this possible? Would I set up a redirect from the dummy store app page to the real app page? – BigBoy1337 Oct 09 '14 at 21:56
  • yes, it will take your user to play store for dummy app because its AAR is listed first in the NDEF of your nfc tag. You always have the flexibility to include what ever you like in your dummy/tracking apk and its play store description...even putting the entire real app inside (ofcourse with tracking package name) if needed. – ashoke Oct 09 '14 at 22:04
  • It would ideal if we could ceate a AAR with `com.example.application&referrer=` format ? you may be able to use [play store campaign](https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#google-play-how) , but [it looks like NFC is not ok in parsing that url as AAR](http://stackoverflow.com/questions/10831239/androidapplicationrecord-and-google-analytics). – ashoke Oct 09 '14 at 22:14
2

If you want to track tag usage for installation/download of your app

Unfortunately, adding tracking parameters to an Android Application Record (AAR) is only partially possible. For instance, you could create an AAR with its package name set to this:

com.example.application&referrer=utm_source%3Dtag1

This AAR would cause Play Store to be opened for your app "com.example.application" and adds a tracking parameter indicating the campaign source "tag1" (based on Google Analytics SDK campaign measurement).

However, this AAR would never cause your app to be opened directly. Regardless of whether your app is installed or not, Play Store would be opened. This is due to the NFC system service not supporting tracking parameters in AARs.

I don't think that ashoke's work around idea of using separate tracking app would be of much use:

  • Your users would need to install a second app besides your main app. Unless, of course, if you integrate the full functionality of your main app in the tracking app.

  • Unless you use a separate tracking app for each tag that you want to track, your users would need to double tap the tag in order to trigger the installation of your main app: Once they would need to tap in order to install the tracking app and once for running the tracking app and passing parameters to it. Thus, you could just as well enforce that double tap with your main app by requiring the user to tap the tag in order to activate the app on the first launch.

An alternative would be to use a URI record instead of the AAR. One option would be to directly use a Play Store URL that includes tracking parameters:

https://play.google.com/store/apps/details?id=com.example.application&referrer=utm_source%3Dtag1

Unfortunately, Android's intent filters do not permit to filter on URL parameters, so you could only register your app to trigger upon any "https://play.google.com/store/apps/details" URL regardless of the package ID. Thus, this option is not really suitable.

The better option would be to provide a redirector web service. For instance, your redirector could have the URL:

http://www.example.com/apps/application/tag1

The web service would then redirect the user to Play Store (either by redirecting to a Play Store URL or to a "market://" URL):

https://play.google.com/store/apps/details?id=com.example.application&referrer=utm_source%3Dtag1

So, if your app is not yet installed on a user's device, tapping the tag would cause the URL "http://www.example.com/apps/application/tag1" to be opend in a web browser (which would in turn open the Play Store page of your app and pass the tracking parameters).

If your app is already installed, you could catch the NDEF_DISCOVERED event for all your tags by registering the following intent filter:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" android:host="www.example.com" android:pathPrefix="/apps/application/" />
</intent-filter>

Within your app, you can then receive the NDEF_DISCOVERED intent and determine the tag that started your app by parsing the URL.

If you don't care which tag triggered the download of your app and you just want to track tag usage when your app is already installed

In that case you would use a regular AAR that contains your app's package name and add an additional NFC Forum external type record as the first record of your NDEF message:

EXT: example.com:tracking PAYLOAD=tag1
AAR: com.example.application

You would then register for that external type:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="vnd.android.nfc"
          android:host="ext"
          android:pathPrefix="/example.com:tracking"/>
</intent-filter>

If your app is not installed, the AAR will make sure that your app's Play Store page is launched. If your app is installed, your app will be started and you can parse the NDEF message that is sent to your app as part of the NDEF_DISCOVERED intent for the NFC Forum external type record.

Community
  • 1
  • 1
Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • can we achieve using AAR alone, even when app not installed...that was my workaround. I like the website redirect url approach you suggest, but it requires him having to use another webservice. – ashoke Oct 10 '14 at 00:03
  • If I was to choose the second option, and not care about tracking unless the user already has the app, would enabling nfc with foreground dispatch change the way that the external type record is implemented? – BigBoy1337 Oct 10 '14 at 16:56
  • I'm not sure what you mean with that. Foreground dispatch is a method to give an activity priority over manifest-registered intent filters for NFC discovery events *while it is visible in the foreground*. – Michael Roland Oct 12 '14 at 15:05
  • ohh man. Im so sorry, I forgot about the bounty. I should have given it to you – BigBoy1337 Oct 15 '14 at 03:27