Prerequisites
- A site that supports HTTPS.
- You can publish changes in GTM for the site’s container.
- Complete the OneSignal Web SDK setup flow until you reach the step Add Code to Site. If you do this, you will have:
- A OneSignal Web Push app created with OneSignal App ID.
- The OneSignal Service Worker setup.
Setup
1. Set up your OneSignal web app
Follow Web SDK setup until you reach the step Add Code to Site. This is where you will get the OneSignal App ID.
Once you reach this step, you will need to make some adjustments to the code to work with Google Tag Manager.
2. Create GTM variables
Create GTM variables for values you may reference across GTM tags. Using variables avoids hardcoding values and makes your setup easier to maintain. Create a OneSignal App ID variable- In GTM, go to Variables > New.
- Choose Constant.
- Name it
os_app_id. - Set the value to your OneSignal App ID.
- Save.

Creating a OneSignal App ID variable
You can now reference your App ID anywhere in GTM using
{{os_app_id}}. - Data Layer Variable (recommended)
- First-Party Cookie
- DOM Variable (advanced)
- In GTM, go to Variables > New.
- Choose Data Layer Variable.
- Name it
external_id. - Set the Data Layer Variable Name to
external_id. - Do not set a default value.
- Save.
An example of how to push the value into the dataLayer will be provided in the next section.
- In GTM, go to Variables > New.
- Variable Type: Data Layer Variable.
- Name it
onesignal_id. - Set the Data Layer Variable Name to
onesignal_id. - Do not set a default value.
- Save.
An example of how to push the value into the dataLayer will be provided in the next section.
The OneSignal ID is generated after subscription. If you plan to populate this value, you must explicitly push it into the dataLayer from a OneSignal callback.
3. Create the OneSignal init tag
- In GTM, go to Tags > New.
- Name the tag:
OneSignal - Init - Tag Type: Custom HTML
- Paste the code below
HTML
- Configure the timing under Advanced Settings > Tag firing options to Once per page.
- Under Triggering, select Initialization - All Pages.

Configuring the OneSignal - Init tag
4. Set External ID & Tags
Setting the External ID is optional but recommended because it allows you to identify users across devices and syncs with your backend.Set external_id & caputure the onesignal_id
Use this tag when you want to:
- Identify users in OneSignal with your own user ID (external_id)
- Capture the OneSignal-generated ID for analytics or downstream GTM usage when no external ID exists
external_id into the dataLayer and using the {{external_id}} variable from step 2 above. For example:
HTML
- Tag name:
OneSignal – Set External ID or Get OneSignal ID - Tag type: Custom HTML
- Tag firing options: Once per page (recommended)
- Trigger: Use with event
OneSignalInitialized(set in the above OneSignal - Init tag)
HTML
Set Data Tags
This step sends User Data Tags to OneSignal using the Web SDK. Tag configuration- Name:
OneSignal - Add Tags. - Tag Type: Custom HTML.
- Tag firing options: Once per page (recommended)
- Trigger:
- Use with event
OneSignalInitialized(set in the above OneSignal - Init tag) - Your condition for the tag to fire (e.g. “Login success”, “Profile page”, “Purchase”, etc.)
- Use with event
HTML
Only send tags when you have the user data available (e.g., after login, after a profile loads, or after a known conversion event).
Consent Mode and privacy considerations
If your site uses Consent Mode / a CMP, decide whether OneSignal should load:- Only after consent (common for EU/UK), or
- Immediately (common where “functional” storage is allowed by default).
Testing
- In GTM, open Preview mode.
-
Load your site and confirm:
OneSignal - Initfires once.OneSignalInitializedappears in the GTM event timeline (if you kept the event push).
- Subscribe to your website. See Web permission prompts for prompting details.
- In the OneSignal dashboard, go to Audience > Subscriptions and confirm a Subscription appears after you opt in. You should also see an External ID if you set one.
- Send a test push from Messages > New Push.
If initialization is working, you’ll see the SDK loaded on the page and subscriptions appearing in OneSignal after opt-in.
Troubleshooting
-
Init tag fires, but SDK never loads
- Check for Content Security Policy (CSP) blocking
https://cdn.onesignal.com. - Check for ad blockers/script blockers.
- Check for Content Security Policy (CSP) blocking
-
dataLayererrors- Ensure
window.dataLayer = window.dataLayer || []is set before anydataLayer.push()calls.
- Ensure
-
Duplicate prompts / duplicate SDK load
- Make sure you are not also loading OneSignal via site code, a CMS plugin, or another GTM tag.
-
Add Tags runs but doesn’t appear in OneSignal
- Confirm the Trigger Group waits for OneSignalInitialized.
- Confirm your user action trigger actually fires.
- Confirm tags are valid key/value pairs and within Plan limits.