Referrer

pub.dev likes popularity pub points

This is a plugin which allows you to read various referrer information.

A referrer is the URL of the webpage (or app) that caused the app to be opened via a deep link.

Most APIs are subject to various platform limitations and they're subject to the referrer policy of the webpage. Therefore, all information read via the APIs of this plugin may not be available due to various reasons.

iOS

On iOS this works by reading NSUserActivity#referrerUrl.

Android

On Android this reads Intent.EXTRA_REFERRER of the last incoming intent. (Related Activity#getReferrer())

It's up to the browser and the webpage's referrer policy to supply a value. On Android, the referrer can also contain the name of the application that startet the app. This means this can not just include the URL, but also other applications.

In general, Chrome does a good job of supplying the referrer information. The referrer is mostly not available when opening a deeplink via Firefox.

Other platforms

On platforms other than Android and iOS calling any method of this plugin results in a no-op.

How to use this?

Here's some examples demonstrating where it may make sense to read the referrer information.

class ReferrerObserver with WidgetsBindingObserver {

  @override  
  Future<bool> didPushRouteInformation(RouteInformation routeInformation) async {
    final referrerInfo = await Referrer().getReferrer();
    // do something with referrerInfo
    return false;
  }
}

// Add the observer somewhere
WidgetsBinding.addObserver(ReferrerObserver())
final _appLinks = AppLinks();

_appLinks.uriLinkStream.listen((uri) async {
    final referrerInfo = await Referrer().getReferrer();
    // do something with referrerInfo
});

Install referrer

This library does not offer tracking of the install referrer. However, there are various other packages that can read the install referrer.

Libraries

referrer