Skip to content

Getting Started

GitHub
Terminal window
npm install @capgo/capacitor-persistent-uuid
npx cap sync
import { PersistentUuid } from '@capgo/capacitor-persistent-uuid';
import { PersistentUuid } from '@capgo/capacitor-persistent-uuid';
const result = await PersistentUuid.getId();
console.log(result.id);
console.log(result.scope);
console.log(result.created);

The first call creates and stores a UUID. Later calls return the same UUID for the same scope.

The native default scope is the package name on Android and the bundle identifier on iOS. If debug and production builds use different package identifiers but should share one UUID, pass a shared scope.

const result = await PersistentUuid.getId({
scope: 'com.example.app',
});

Call resetId when the user logs out, requests a privacy reset, or when automated tests need a new identifier.

const replacement = await PersistentUuid.resetId();
console.log(replacement.id);
  • Android can survive uninstall and reinstall, including Android Studio and Play installs with different signing keys, when the package name or custom scope is stable.
  • iOS survives app updates and iOS updates while Keychain access rules remain the same.
  • Web uses localStorage and is only a development fallback.

If you are using Getting Started to add persistent app identity, connect it with @capgo/capacitor-persistent-uuid for the overview, Android behavior for reinstall behavior, iOS behavior for Keychain behavior, Using @capgo/capacitor-persistent-uuid for the tutorial, and Capgo Plugin Directory for other native plugins.