Visitor Tracking Between an App and Mobile Web

Visitor Tracking Between an App and Mobile Web

If your app opens mobile web content, you need to take extra steps to ensure that visitors are not separately identified as they move between the native and mobile web in a hybrid app.

Visitor IDs within Apps

The SDK generates a unique visitor ID when an app is installed. This app visitor ID is stored within persistent memory on the mobile device and is sent with every hit. The app visitor ID is removed only when the user uninstalls the app (app visitor IDs persist through upgrades).

Visitor IDs within Mobile Web

Typical mobile web implementations use the same standard Analytics s_code.js or AppMeasurement.js that is used within desktop sites. The JavaScript libraries have their own methods of generating unique visitor IDs, which causes a different visitor ID to be generated when you open mobile web content from your app.

To use the same visitor ID in the app and mobile web, complete the following instructions to pass the app visitor ID to the mobile web.

How to Track

Prerequisites: Add the library to your project and implement lifecycle.

  1. Import the library:
  2. Create a method to retrieve the app visitor ID from the SDK:
    protected static String retrieveVisitorIdentification() {
    	// check to see if a custom ID is set.
    	String visitorId = Config.getUserIdentifier();
    	if (visitorId == null || visitorId.length() <= 0) {
    		// if a custom ID was not set, get the default ID.
    		visitorId = Analytics.getTrackingIdentifier();
    	return visitorId;
  3. When you open mobile web content from your application, pass the app visitor ID as query parameter:
    String urlString = "" + retrieveVisitorIdentification();
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
  4. Add the following JavaScript code to the s_doPlugins() function in your Analytics s_code.js or AppMeasurement.js file that is included on the mobile web content to set the visitor ID that you passed:
    if (s.getQueryParam("appvi")) {
    	s.new_vi_date=new Date;
    	s.new_vi_date.setFullYear(s.new_vi_date.getFullYear() + 5);
    else if (s.c_r("app_vi")) {

    This code retrieves the app visitor ID from the query string, stores that value into a five-year cookie, and uses that value moving forward on the mobile web site (whether the app visitor ID is present within the URL or not). The custom visitor ID will appear as the 'vid' parameter on hits from mobile web content.


On hits from the mobile web content, verify that the 'vid' parameter is present on each hit, and that this value matches 'aid' (if you are not setting custom IDs using setUserIdentifier), or matches 'vid' (if you are setting custom IDs by calling setUserIdentifier).

Parent topic: Android SDK Reference