> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Web SDKマッピング

> レガシーPlayer Modelと新しいUser Model間でOneSignal Web SDKメソッドを比較します。TypeScriptベースのコード例と更新されたメソッドリファレンスで実装を移行する方法を学びます。

<Warning>
  OneSignalは、デバイス中心モデル（Player ID）からユーザー中心モデル（OneSignal ID）に更新されました。移行ガイダンスについては、[User Model Migration Guide](./user-model-migration-guide)を参照してください。

  レガシーデバイス中心実装のドキュメントについては、[Version 9](/v9.0/docs/web-push-sdk)を参照してください。
</Warning>

## 概要

このドキュメントでは、OneSignalのレガシー**Player Model Web SDK**から新しい**User Model** SDKへのメソッド、プロパティ、イベントをマッピングします。各セクションには一致するTypeScriptコード例が含まれており、統合を更新する方法を明確に示しています。

すべての例はデモンストレーション目的で簡素化されています。完全で最新の実装については、各メソッドまたはイベントの下に提供されているドキュメントリンクを参照してください。

## OneSignal Service Worker

`OneSignalSDKWorker.js`ファイルのインポートを更新します：

**Player Model:**

```javascript theme={null}
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
```

**User Model:**

```javascript theme={null}
importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");
```

ファイルパスは同じままにします。`importScripts` URLのみを更新してください。

詳細については、[OneSignal Service Worker](./onesignal-service-worker)を参照してください。

## 初期化

### `init()`

**Player Model:** [Docs](/v9.0/docs/web-push-sdk)

```html theme={null}
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
  OneSignal.init({
    appId: "YOUR_APP_ID"
  });
});
</script>
```

**User Model:** [Docs](./mobile-sdk-reference#initialize)

```html theme={null}
<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
window.OneSignalDeferred = window.OneSignalDeferred || [];
OneSignalDeferred.push(async function(OneSignal) {
  await OneSignal.init({
    appId: "YOUR_APP_ID",
  });
});
</script>
```

### `provideUserConsent()`

**Player Model:** [Docs](/v9.0/docs/web-push-sdk)

```typescript theme={null}
OneSignal.provideUserConsent(true)
```

**User Model:** [Docs](./mobile-sdk-reference#setconsentgiven)

```typescript theme={null}
OneSignal.setConsentGiven(true)
```

## プッシュの登録

### `showNativePrompt()`

**Player Model:**

```typescript theme={null}
OneSignal.showNativePrompt()
```

**User Model:** [Docs](./mobile-sdk-reference#requestpermission-fallbacktosettings-push)

```typescript theme={null}
OneSignal.Notifications.requestPermission()
```

### `registerForPushNotifications()` — Dropped in User Model

```typescript theme={null}
OneSignal.registerForPushNotifications()
```

### `#permissionPromptDisplay`

**Player Model:**

```typescript theme={null}
OneSignal.on('permissionPromptDisplay', () => ...)
```

**User Model:** [Docs](./web-sdk-reference#addeventlistener-push-notification)

```typescript theme={null}
OneSignal.Notifications.addEventListener('permissionPromptDisplay', event => { ... })
```

### `showSlidedownPrompt()`

**Player Model:**

```typescript theme={null}
OneSignal.showSlidedownPrompt()
```

**User Model:** [Docs](./web-sdk-reference#promptpush)

```typescript theme={null}
OneSignal.Slidedown.promptPush()
```

### `showHttpPrompt()` — Dropped in User Model

```typescript theme={null}
OneSignal.showHttpPrompt()
```

### `showCategorySlidedown()`

**Player Model:**

```typescript theme={null}
OneSignal.showCategorySlidedown()
```

**User Model:** [Docs](./web-sdk-reference#promptpushcategories)

```typescript theme={null}
OneSignal.Slidedown.promptPushCategories()
```

### `#getNotificationPermission`

**Player Model:**

```typescript theme={null}
OneSignal.on('getNotificationPermission', (permission) => ...)
```

**User Model:** [Docs](./web-sdk-reference#addeventlistener-push-subscription)

```typescript theme={null}
OneSignal.User.PushSubscription.addEventListener('change', ({ optedIn }) => { ... })
```

### `isPushNotificationsSupported()`

**Player Model:**

```typescript theme={null}
OneSignal.isPushNotificationsSupported()
```

**User Model:** [Docs](./web-sdk-reference#ispushsupported)

```typescript theme={null}
OneSignal.Notifications.isPushSupported()
```

### `isPushNotificationsEnabled()`

**Player Model:**

```typescript theme={null}
await OneSignal.isPushNotificationsEnabled()
```

**User Model:** [Docs](./web-sdk-reference#optedin)

```typescript theme={null}
OneSignal.User.PushSubscription.optedIn
```

### `#subscriptionChange`

**Player Model:**

```typescript theme={null}
OneSignal.on('subscriptionChange', (subscribed) => ...)
```

**User Model:**

```typescript theme={null}
OneSignal.User.PushSubscription.addEventListener('change', ({ token }) => { ... })
```

## 分析

### `#notificationPermissionChange`

**Player Model:**

```typescript theme={null}
OneSignal.on('notificationPermissionChange', ({ to }) => ...)
```

**User Model:** [Docs](./web-sdk-reference#permissionchange)

```typescript theme={null}
OneSignal.Notifications.addEventListener('permissionChange', permission => { ... })
```

### `#popoverShown`

**Player Model:**

```typescript theme={null}
OneSignal.on('popoverShown', () => ...)
```

**User Model:** [Docs](./web-sdk-reference#addeventlistener-slidedown)

```typescript theme={null}
OneSignal.Slidedown.addEventListener('slidedownShown', presented => { ... })
```

### `#customPromptClick`

**Player Model:**

```typescript theme={null}
OneSignal.on('customPromptClick', ({ result }) => ...)
```

**User Model:** [Docs](./web-sdk-reference#click)

```typescript theme={null}
OneSignal.Notifications.addEventListener('click', ({notification, result}) => { ... })
```

## ユーザーID

### `getUserId()`

**Player Model:**

```typescript theme={null}
OneSignal.getUserId()
```

**User Model:** [Docs](./web-sdk-reference#id)

```typescript theme={null}
OneSignal.User.PushSubscription.id;
```

### `setExternalUserId()`

**Player Model:** [Docs](./users)

```typescript theme={null}
OneSignal.setExternalUserId("external id")
```

**User Model:** [Docs](./web-sdk-reference#login-external-id)

```typescript theme={null}
OneSignal.login("external id")
```

### `removeExternalUserId()`

**Player Model:**

```typescript theme={null}
OneSignal.removeExternalUserId()
```

**User Model:** [Docs](./web-sdk-reference#logout)

```typescript theme={null}
OneSignal.logout()
```

### `getExternalUserId()`

**Player Model:**

```typescript theme={null}
await OneSignal.getExternalUserId()
```

**User Model:** [Docs](./web-sdk-reference#externalid)

```typescript theme={null}
OneSignal.User.externalId
```

## タグ

### `sendTag()`

**Player Model:**

```typescript theme={null}
OneSignal.sendTag("key", "value")
```

**User Model:**

```typescript theme={null}
OneSignal.User.addTag("key", "value")
```

**User Model** [doc](./web-sdk-reference#addtag-%2C-addtags)

### `sendTags()`

**Player Model:**

```typescript theme={null}
OneSignal.sendTags({ key1: 'value1', key2: 'value2' })
```

**User Model:**

```typescript theme={null}
OneSignal.User.addTags({ key1: 'value1', key2: 'value2' })
```

### `getTags()`

**Player Model:**

```typescript theme={null}
await OneSignal.getTags()
```

**User Model:**

```typescript theme={null}
OneSignal.User.getTags()
```

### `deleteTag()`

**Player Model:**

```typescript theme={null}
OneSignal.deleteTag("key")
```

**User Model:**

```typescript theme={null}
OneSignal.User.removeTag("key")
```

### `deleteTags()`

**Player Model:**

```typescript theme={null}
OneSignal.deleteTags(["key1", "key2"])
```

**User Model:**

```typescript theme={null}
OneSignal.User.removeTags(["key1", "key2"])
```

## プッシュ通知

### `sendSelfNotification()` — Dropped in User Model

```typescript theme={null}
OneSignal.sendSelfNotification('title', 'message', 'url')
```

### `setSubscription()`

**Player Model:**

```typescript theme={null}
OneSignal.setSubscription(false)
```

**User Model:**

```typescript theme={null}
OneSignal.Notifications.permission = false
```

## 通知の受信

### `#notificationDisplay`

**Player Model:**

```typescript theme={null}
OneSignal.on('notificationDisplay', (event) => { ... })
```

**User Model:**

```typescript theme={null}
OneSignal.Notifications.addEventListener('foregroundWillDisplay', ({ notification }) => { ... })
```

### `#notificationDismiss`

**Player Model:**

```typescript theme={null}
OneSignal.on('notificationDismiss', (event) => { ... })
```

**User Model:**

```typescript theme={null}
OneSignal.Notifications.addEventListener('dismiss', ({ notification }) => { ... })
```

### `#addListenerForNotificationOpened`

**Player Model:**

```typescript theme={null}
OneSignal.on('addListenerForNotificationOpened', (event) => { ... })
```

## メール

### `setEmail()`

**User Model** [doc](./web-sdk-reference#addemail-%2C-removeemail)

**Player Model:**

```typescript theme={null}
OneSignal.setEmail('email@example.com')
```

**User Model:**

```typescript theme={null}
OneSignal.User.addEmail('email@example.com')
```

### `logoutEmail()`

**Player Model:**

```typescript theme={null}
OneSignal.logoutEmail()
```

**User Model:**

```typescript theme={null}
OneSignal.User.removeEmail('email@example.com')
```

### `getEmailId()` — Dropped in User Model

## SMS

### `setSMSNumber()`

**Player Model:**

```typescript theme={null}
OneSignal.setSMSNumber('+11234567890')
```

**User Model:**

```typescript theme={null}
OneSignal.User.addSms('+11234567890')
```

### `logoutSMSNumber()`

**Player Model:**

```typescript theme={null}
OneSignal.logoutSMS()
```

**User Model:**

```typescript theme={null}
OneSignal.User.removeSms('+11234567890')
```

***
