Skip to main content
Use this API to obtain the Mini Program App ID synchronously without requiring callbacks or promises.

Return Value

PropertyTypeDescription
appIdStringThe identifier of the current Mini Program
The returned App ID depends on the deployment context:
  • Deployed to AlipayCN: Returns the ID assigned by AlipayCN
  • Other deployments: Returns the ID assigned by Mini Program Platform

Code Example

// Get App ID synchronously
const result = my.getAppIdSync();
console.log('App ID:', result.appId);

// Use in page
Page({
  onLoad() {
    const { appId } = my.getAppIdSync();
    this.setData({ appId });
  },

  data: {
    appId: ''
  }
});

Use Cases

Conditional Logic Based on App ID

Page({
  onLoad() {
    const { appId } = my.getAppIdSync();

    // Different behavior for different app versions
    if (appId === 'your-production-app-id') {
      this.initProductionFeatures();
    } else {
      this.initDevelopmentFeatures();
    }
  }
});

Logging and Analytics

function logEvent(eventName, data) {
  const { appId } = my.getAppIdSync();

  my.request({
    url: 'https://analytics.example.com/log',
    method: 'POST',
    data: {
      appId,
      event: eventName,
      ...data
    }
  });
}

Notes

  • This is a synchronous operation that returns immediately
  • The App ID is stable and does not change during the Mini Program lifecycle
  • For AlipayCN deployments, cross-reference with the Mini Program Platform to find the official Mini Program ID

my.getRunScene

Get the running environment

my.SDKVersion

Get SDK version