{"id":19251020,"url":"https://github.com/onesignal/onesignal-ngx","last_synced_at":"2025-04-21T12:33:37.588Z","repository":{"id":38235005,"uuid":"405230175","full_name":"OneSignal/onesignal-ngx","owner":"OneSignal","description":"OneSignal Angular","archived":false,"fork":false,"pushed_at":"2023-10-17T19:30:11.000Z","size":210,"stargazers_count":5,"open_issues_count":4,"forks_count":5,"subscribers_count":33,"default_branch":"main","last_synced_at":"2024-11-07T17:20:29.416Z","etag":null,"topics":["angular","email","in-app-messaging","ngx","notifications","onesignal","plugin","push","push-notifications","sms","web"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OneSignal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-10T22:46:31.000Z","updated_at":"2024-05-09T03:59:46.000Z","dependencies_parsed_at":"2023-01-31T10:01:21.410Z","dependency_job_id":"fe675b9f-e308-4101-ba1e-a4ca073cc38f","html_url":"https://github.com/OneSignal/onesignal-ngx","commit_stats":{"total_commits":23,"total_committers":5,"mean_commits":4.6,"dds":"0.30434782608695654","last_synced_commit":"2b941a9835ea6d54b4d620a3cc4e3b4c05dd5592"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-ngx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-ngx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-ngx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-ngx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OneSignal","download_url":"https://codeload.github.com/OneSignal/onesignal-ngx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223864862,"owners_count":17216422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","email","in-app-messaging","ngx","notifications","onesignal","plugin","push","push-notifications","sms","web"],"created_at":"2024-11-09T18:19:38.452Z","updated_at":"2025-04-21T12:33:37.565Z","avatar_url":"https://github.com/OneSignal.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eWelcome to onesignal-ngx 👋\u003c/h1\u003e\n\n\u003cp\u003e\n  \u003ca href=\"https://www.npmjs.com/package/onesignal-ngx\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Version\" src=\"https://img.shields.io/npm/v/onesignal-ngx.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/OneSignal/onesignal-ngx#readme\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Documentation\" src=\"https://img.shields.io/badge/documentation-yes-brightgreen.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/OneSignal/onesignal-ngx/graphs/commit-activity\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Maintenance\" src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://twitter.com/onesignal\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Twitter: onesignal\" src=\"https://img.shields.io/twitter/follow/onesignal.svg?style=social\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e This is a JavaScript module that can be used to easily include [OneSignal](https://onesignal.com/) code in a website that uses Angular for its front-end codebase.\n\n- 🏠 [Homepage](https://onesignal.com)\n- 🖤 [npm](https://www.npmjs.com/package/onesignal-ngx)\n\nOneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 2 million+ businesses to send 9 billion Push Notifications per day.\n\nYou can find more information on OneSignal [here](https://onesignal.com/).\n\n\u003e Upgrading from Version 1?\n\u003e See our [migration guide](./MigrationGuide.md) to get started.\n\n## Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#onesignal-api)\n- [Advanced Usage](#advanced-usage)\n\n---\n\n## Install\n\n### npm\n\n```bash\nnpm install --save onesignal-ngx\n```\n\n### yarn\n\n```bash\nyarn add onesignal-ngx\n```\n\n---\n\n## Library setup\n\n```js\nimport { OneSignal } from 'onesignal-ngx';\n```\n\nInitialize OneSignal with your `appId` via the `options` parameter:\n\n```js\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css']\n})\nexport class AppComponent {\n  title = 'angular-example-app';\n\n  constructor(private oneSignal: OneSignal) {\n    this.oneSignal.init({\n      appId: \"8e7fe838-fbcd-4152-980d-32565a2dcf03\",\n    });\n  }\n}\n```\n\nThe `init` function returns a promise that resolves when OneSignal is loaded.\n\n**Examples**\n\n```js\nawait this.oneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });\n// do other stuff\n```\n\n```js\nthis.oneSignal\n  .init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' })\n  .then(() =\u003e {\n    // do other stuff\n  });\n```\n\n### Init Options\n\nYou can pass other options to the `init` function. Use these options to configure personalized prompt options, auto-resubscribe, and more ([full list of initialization options](https://documentation.onesignal.com/v11.0/docs/web-sdk#init)).\n\n\u003cdetails\u003e\n  \u003csummary\u003eExpand to see more options\u003c/summary\u003e\n\n| Property Name                    | Type                 | Description                                              |\n| -------------------------------- | -------------------- | -------------------------------------------------------- |\n| `appId`                          | `string`             | The ID of your OneSignal app.                            |\n| `autoRegister`                   | `boolean` (optional) | Whether or not to automatically register the user.       |\n| `autoResubscribe`                | `boolean` (optional) | Whether or not to automatically resubscribe the user.    |\n| `path`                           | `string` (optional)  | The path to the OneSignal service worker file.           |\n| `serviceWorkerPath`              | `string` (optional)  | The path to the OneSignal service worker script.         |\n| `serviceWorkerUpdaterPath`       | `string` (optional)  | The path to the OneSignal service worker updater script. |\n| `subdomainName`                  | `string` (optional)  | The subdomain of your OneSignal app.                     |\n| `allowLocalhostAsSecureOrigin`   | `boolean` (optional) | Whether or not to allow localhost as a secure origin.    |\n| `requiresUserPrivacyConsent`     | `boolean` (optional) | Whether or not the user's consent is required.           |\n| `persistNotification`            | `boolean` (optional) | Whether or not notifications should persist.             |\n| `notificationClickHandlerMatch`  | `string` (optional)  | The URL match pattern for notification clicks.           |\n| `notificationClickHandlerAction` | `string` (optional)  | The action to perform when a notification is clicked.    |\n| `welcomeNotification`            | `object` (optional)  | The welcome notification configuration.                  |\n| `notifyButton`                   | `object` (optional)  | The notify button configuration.                         |\n| `promptOptions`                  | `object` (optional)  | Additional options for the subscription prompt.          |\n| `webhooks`                       | `object` (optional)  | The webhook configuration.                               |\n| `[key: string]`                  | `any`                | Additional properties can be added as needed.            |\n\n**Service Worker Params**\nYou can customize the location and filenames of service worker assets. You are also able to specify the specific scope that your service worker should control. You can read more [here](https://documentation.onesignal.com/docs/onesignal-service-worker-faq#sdk-parameter-reference-for-service-workers).\n\nIn this distribution, you can specify the parameters via the following:\n\n| Field                | Details                                                                                                              |\n| -------------------- | -------------------------------------------------------------------------------------------------------------------- |\n| `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: \"/js/push/onesignal/\" }` |\n| `serviceWorkerPath`  | The path to the service worker file.                                                                                 |\n\n\u003c/details\u003e\n\n---\n\n**Example**:\n\n```js\nthis.oneSignal.init({\n  appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',\n  serviceWorkerParam: {\n    scope: '\u003cpath scope\u003e',\n  },\n  serviceWorkerPath: '\u003cpath\u003e',\n});\n```\n\n### Service Worker File\n\nIf you haven't done so already, you will need to add the [OneSignal Service Worker file](https://github.com/OneSignal/OneSignal-Website-SDK/files/11480764/OneSignalSDK-v16-ServiceWorker.zip) to your site ([learn more](https://documentation.onesignal.com/docs/web-push-quickstart#step-6-upload-files)).\n\nThe OneSignal SDK file must be publicly accessible. You can put it in your top-level root or a subdirectory. However, if you are placing the file not on top-level root make sure to specify the path via the service worker params in the init options (see section above).\n\n**Tip:**\nVisit `https://yoursite.com/OneSignalSDKWorker.js` in the address bar to make sure the file is being served successfully.\n\n**Troubleshooting:**\nIf you uploaded the file but you cannot access it via your browser search bar, make sure you have told Angular about it via the `assets` param in your `angular.json` file.\n\n---\n\n### Typescript\n\nThis package includes Typescript support.\n\n```ts\nclass OneSignal {\n  Slidedown: IOneSignalSlidedown;\n  Notifications: IOneSignalNotifications;\n  Session: IOneSignalSession;\n  User: IOneSignalUser;\n  Debug: IOneSignalDebug;\n  login(externalId: string, jwtToken?: string): Promise\u003cvoid\u003e;\n  logout(): Promise\u003cvoid\u003e;\n  init(options: IInitObject): Promise\u003cvoid\u003e;\n  setConsentGiven(consent: boolean): Promise\u003cvoid\u003e;\n  setConsentRequired(requiresConsent: boolean): Promise\u003cvoid\u003e;\n}\n```\n\n### OneSignal API\n\nSee the official [OneSignal WebSDK reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for information on all available SDK functions.\n\n---\n\n## Advanced Usage\n\n### Events and Event Listeners\n\nUse listeners to react to OneSignal-related events:\n\n### Notifications Namespace\n\n| Event Name                | Callback Argument Type                 |\n| ------------------------- | -------------------------------------- |\n| 'click'                   | NotificationClickEvent                 |\n| 'foregroundWillDisplay'   | NotificationForegroundWillDisplayEvent |\n| 'dismiss'                 | NotificationDismissEvent               |\n| 'permissionChange'        | boolean                                |\n| 'permissionPromptDisplay' | void                                   |\n\n### Slidedown Namespace\n\n| Event Name       | Callback Argument Type |\n| ---------------- | ---------------------- |\n| 'slidedownShown' | boolean                |\n\n### Push Subscription Namespace\n\n| Event Name | Callback Argument Type |\n| ---------- | ---------------------- |\n| 'change'   | boolean                |\n\n**Example**\n\n```js\nthis.oneSignal.Notifications.addEventListener('click', (event) =\u003e {\n  console.log('The notification was clicked!', event);\n});\n```\n\nSee the [OneSignal WebSDK Reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for more info on the available event listeners.\n\n## Troubleshooting\n\n### Service Worker Issues\n\n#### Check the `serviceWorker` flag\n\nIn your `angular.json`, see if the `serviceWorker` flag is set to `true`. The flag is used to cause the production build to include some extra service worker files that will conflict with the OneSignal worker if they use the same scope. If your web app depends on this flag being true and hence the Angular service worker (`ngsw-worker.js`) like in PWA setups, you should customize your OneSignal service worker integration to use a different scope than the Angular service worker. Otherwise, they will conflict. This can be done using the service worker OneSignal initialization params documented above. [Click for further details](https://documentation.onesignal.com/docs/troubleshooting-web-push#pwa-or-multiple-service-workers).\n\n---\n\n## 🤝 Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr/\u003eFeel free to check [issues page](https://github.com/OneSignal/onesignal-ngx/issues).\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n## OneSignal\n\n- [Website](https://onesignal.com)\n- Twitter: [@onesignal](https://twitter.com/onesignal)\n- Github: [@OneSignal](https://github.com/OneSignal)\n- LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)\n\n## Discord\n\nReach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)!\n\n## 📝 License\n\nCopyright © 2023 [OneSignal](https://github.com/OneSignal).\u003cbr /\u003e\nThis project is [MIT](https://github.com/OneSignal/onesignal-ngx/blob/main/LICENSE) licensed.\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonesignal%2Fonesignal-ngx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonesignal%2Fonesignal-ngx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonesignal%2Fonesignal-ngx/lists"}