Hello! This is the public repo of the mParticle Web SDK. We've built the mParticle platform to take a new approach to web and mobile app data and the platform has grown to support 300+ integrations including analytics, data warehouses, and marketing automation. mParticle is designed to serve as the connector between all of these services - check out our site, or hit us at developers@mparticle.com to learn more.
Fully detailed documentation and other information about mParticle web SDK can be found at our doc site here
Version 3 of the mParticle Web SDK is generally available. See MIGRATING.md for the in-repo upgrade steps, the 3.0.0 changelog for the full commit list, and the Upgrade to Version 3 guide on the docs site.
There are two ways to initialize the SDK, either via a script tag, or you can bundle the SDK via NPM. A summary of steps for both is available below, but you should review the detailed documentation for the script tag and self hosting on the mParticle docs site.
To integrate the SDK add the following snippet to your site after customizing mParticle.config, ideally in the <head> element. Replace REPLACE WITH API KEY at the end of the snippet with the API key for your mParticle Web workspace.
This snippet pre-populates method stubs for much of the public SDK API, allowing immediate reference to these APIs as the SDK loads.
<script type="text/javascript">
//configure the SDK
window.mParticle = {
config: {
isDevelopmentMode: true,
identifyRequest: {
userIdentities: {
email: 'email@example.com',
customerid: '123456',
},
},
identityCallback: function(result) {
// Do something once an identity call has been made.
// For more information, see https://docs.mparticle.com/developers/sdk/web/idsync/#sdk-initialization-and-identify
console.log(result);
},
dataPlan: {
planId: 'my_plan_id',
planVersion: 2
}
},
};
//load the SDK
(function(e){window.mParticle=window.mParticle||{};window.mParticle.EventType={Unknown:0,Navigation:1,Location:2,Search:3,Transaction:4,UserContent:5,UserPreference:6,Social:7,Other:8,Media:9};window.mParticle.eCommerce={Cart:{}};window.mParticle.Identity={};window.mParticle.Rokt={};window.mParticle.config=window.mParticle.config||{};window.mParticle.config.rq=[];window.mParticle.config.snippetVersion=3.1;window.mParticle.ready=function(e){window.mParticle.config.rq.push(e)};var i=["endSession","logError","logBaseEvent","logEvent","logForm","logLink","logPageView","setSessionAttribute","setAppName","setAppVersion","setOptOut","setPosition","startNewSession","startTrackingLocation","stopTrackingLocation"];var t=["setCurrencyCode"];var n=["identify","login","logout","modify","search"];var o=["selectPlacements","hashAttributes","hashSha256","setExtensionData","use","getVersion","terminate","onShoppableAdsReady","setPrivacyControl"];i.forEach(function(e){window.mParticle[e]=r(e)});t.forEach(function(e){window.mParticle.eCommerce[e]=r(e,"eCommerce")});n.forEach(function(e){window.mParticle.Identity[e]=r(e,"Identity")});o.forEach(function(e){window.mParticle.Rokt[e]=r(e,"Rokt")});function r(i,t){if(t){i=t+"."+i}return function(){var e=Array.prototype.slice.call(arguments);e.unshift(i);window.mParticle.config.rq.push(e)}}var a,c,s=window.mParticle.config,l=s.isDevelopmentMode?1:0,w="?env="+l,d=window.mParticle.config.dataPlan;if(d){a=d.planId;c=d.planVersion;if(a){if(c&&(c<1||c>1e3)){c=null}w+="&plan_id="+a+(c?"&plan_version="+c:"")}}var m=window.mParticle.config.versions;var f=[];if(m){Object.keys(m).forEach(function(e){f.push(e+"="+m[e])})}var p=document.createElement("script");p.type="text/javascript";p.charset="utf-8";p.async=true;p.src="https://jssdkcdns.mparticle.com/js/v3/"+e+"/mparticle.js"+w+"&"+f.join("&");var P=document.getElementsByTagName("script")[0];P.parentNode.insertBefore(p,P)})("REPLACE WITH API KEY");You can then log events, for example, as follows:
mParticle.logEvent('Play Movie', mParticle.EventType.Navigation, {
movie_length: '127 minutes',
rating: 'PG',
});mParticle.Rokt.setPrivacyControl sets page-scoped privacy flags for Rokt Ads,
even when no Rokt kit is loaded:
mParticle.Rokt.setPrivacyControl({ noTargeting: true, noFunctional: true });The object accepts noTargeting, noFunctional and doNotShareOrSell booleans
(IRoktPrivacyControl for TypeScript). Each call updates only the flags passed
as booleans. Omitted and non-boolean values leave the flag unchanged. Each page
flag defaults to false. Pass false to clear that page flag without clearing
initialization or derived opt-outs. $NoTargeting is set to true or removed
from the current user's profile according to the combined targeting flag.
Snippet version 3.1 queues calls before load. It applies the queued privacy
updates in order before SDK initialization and the other queued calls. A later
queued call overrides an earlier one before anything else runs, so the last
queued value applies to every call queued before load. With an older
snippet, call after load or feature-detect the method. A change applies straight
away, as a consent change does: noFunctional stops the SDK's storage and removes
what it stored, apart from the user and device IDs and consent choices it keeps,
and a loaded Rokt kit uses the flags on its next call. Pass the same flags in
launcherOptions at initialization on the next page load; they are not saved as
preferences.
In your root project directory, add the SDK to your package.json:
npm install @mparticle/web-sdk
// index.js
import mParticle from '@mparticle/web-sdk';
let mParticleConfig = {
isDevelopmentMode: true,
identifyRequest: {
userIdentities: {
email: 'email@example.com',
customerid: '123456',
},
},
identityCallback: myIdentityCallback,
dataPlan: {
planId: 'my_plan_id',
planVersion: 2,
},
};
mParticle.init('REPLACE WITH API KEY', mParticleConfig);You can then log events, for example, as follows:
mParticle.logEvent('Play Movie', mParticle.EventType.Navigation, {
movie_length: '127 minutes',
rating: 'PG',
});If you configure mParticle via a snippet tag, the Web SDK is able to automatically include, initialize, and delegate API calls to 3rd-party SDKs. Otherwise you will install them via npm. For more instructions on installing via npm, view the documentation.
If you would like to add your company as a new Javascript integration, reference the following integrations as examples:
- Amplitude
- Appboy
- BingAds
- Device Match
- Google Analytics
- Inspectlet
- Intercom
- Kahuna
- Kissmetrics
- Localytics
- Mixpanel
- Optimizely
- SimpleReach
See CONTRIBUTING.md.
The test script will run all tests using Karma and ChromeHeadless, and Firefox by default. To run tests using a different browser, use the command:
$ BROWSER=[browserBrand] npm run testBrowser
where browserBrand can be another browser such as Edge or IE.
This package comes with the NPM package pre-commit, which will run ESLint when you try to commit.
V2 and V3 release with separate workflows: staging-step-1.yml,
staging-step-2.yml and staging-step-3.yml for v2, and
v3-release-step-1.yml, v3-release-step-2.yml and v3-release-step-3.yml
for v3.
V2 Release - Step 1 runs only from staging; V2 Release - Step 2
and V2 Release - Step 3 run only from master. These workflows have no
track or resumeKitReleaseTag input and do not publish V3 kits or stage V3
candidates. V3 releases and kit recovery use only the v3-release-step-*.yml
workflows: Step 1 from a release tag on main in Release Please mode, or
from v3-staging in legacy branch mode; Steps 2 and 3 from main.
The last V3 release cut by semantic-release, whose Step 3 brings main level
with v3-development, ends that path. Every later V3 release is cut from
main by Release Please, as the next section describes, and v3-development
is retired.
V3 pull requests merge to main. Release Please reads their Conventional
Commit titles and cuts each V3 release from main:
- V3 Release Please (
v3-release-please.yml) keeps one release pull request open onmain. It carries the next version, the changelog entry and the version of every kit. - On each push to that pull request, V3 Release Please - Commit Release
Bundles builds core and every kit at that version and commits
dist/andkits/**/dist, signed by the release machine user and pushed by the release app. The check V3 release bundles match version passes once the committed bundles match that build. No other pull request tomainmay changedist/orkits/**/dist(the check V3 bundles change only in release PRs). - Before merging the release pull request, check that it does not show "This
branch is out-of-date with the base branch". If it does, wait for Release
Please to rewrite it and for V3 release bundles match version to go
green again. Hold other merges to
mainfor a couple of minutes while you merge. Release Please publishes the GitHub release, creates thev3.X.Ytag on the merge commit, and dispatches V3 Release - Step 1 (v3-release-step-1.yml) on that tag withdryRun=false. - V3 Release - Step 1 checks that the tag is on
main, builds the distribution bundle, rebuilds core and every kit and compares them with the tag's bundles, and runs the test suites. Once the build, bundle check and tests pass, it publishes core and every kit to npmnext, movesv3-stagingforward to the tag commit, and uploads and stages the V3 candidate in S3. If the automatic dispatch from Release Please did not start Step 1 (or if Step 1 failed before packaging or staging started and needs to be started manually), run V3 Release - Step 1 manually from that tag (in Use workflow from, choose the tag, not a branch) withdryRun=false: it skips every package npm already holds with the same bytes. If a Step 1 run stops part-way after packaging or staging, use Re-run failed jobs on that original Step 1 run (see Recover an incomplete v3 kit publication). A Step 1 run from a tag runs only while the repository variableV3_RELEASE_PLEASE_ENABLEDistrue, and a run fromv3-stagingfails once it is. - Run Steps 2 and 3 from
mainas described below. Step 3 pushes only the three release-order branches, becausemainalready holds the release. Don't changeV3_RELEASE_PLEASE_ENABLEDwhile a Step 3 run or its S3 promote is in progress. If a promote skipped because the variable changed, runpromote-gaby hand.
main moves to the new version when the release pull request merges, and
ga serves it only after promote-ga. In that window main is ahead of
ga on every release. This is expected, and the gap closes at promote-ga.
To roll a release back, follow Roll back a V3 release below.
Set the repository variable V3_DIST_GUARD_ENABLED to true once the first
Release Please release pull request's bundle commit shows as Verified on
GitHub. Until then, V3 bundles change only in release PRs passes with a
note. Then add it and V3 release bundles match version to the required
checks on main. When V3_DIST_GUARD_ENABLED is first set, or set again,
re-run V3 bundles change only in release PRs on every open pull request to
main. Each of them passed with a note while the variable was unset, and that
result stands until the check runs again.
A rollback changes S3 channel pointers, not npm packages or Git history. Each channel selects core and every V3 Web SDK kit from one candidate; there is no per-kit S3 rollback. For a single-kit defect, roll back the whole release or publish a fix release.
Pods default to qa. Production and QA require two separate dispatches:
choose all-production for us1, us2, st1, eu1 and au1, then qa.
There is no combined production-plus-QA choice. An individual production pod
can also be selected.
Choose the action by the problem:
| Problem | Action |
|---|---|
| One channel serves a bad release | rollback with that channel and the known-good version/build. |
| A release must stop everywhere | Stop its running workflows first, then rollback-all in production and QA. |
| Restore one deliberately rolled-back channel | rollback with allow_upgrade=true, not promote-ga. |
| Replace one build of the same version | Explicit build_id plus allow_rebuild=true; distinguish pointer-only replacement from a canonical rebuild below. |
| Core published but some kits did not | Complete Recover an incomplete v3 kit publication before any newer release. |
| The published package itself is bad | Prefer a fix-forward release with a new version; a pointer rollback cannot retract npm packages. |
In GitHub Actions, select V3 shadow release: move release pointers
(v3-shadow-promote.yml) and Use workflow from: main. Maintainers need
permission to dispatch the workflow and must satisfy any configured deployment
protection before a live move.
- Set
operation=rollback,channeltoga,v3-stagingor one ofv3-release-order-a,v3-release-order-b,v3-release-order-c,versionto the stable version without avprefix (for example3.12.0), andpodsto the intended selection. Setdry_run=true,allow_downgrade=true,allow_rebuild=false,allow_upgrade=false. - Supply the known-good
build_id. If it is unknown, leave it blank for this first preview only: the release index resolves the version's build. A version absent from that index needs an explicit build. Inspect the resolved candidate and every selected pod's planned before/after move. - Copy that exact resolved
build_idinto the live dispatch, keeping the same version, channel, pods and flags. Change onlydry_run=false. Use that explicit build for both the production and QA dispatches, so a later release-index change cannot silently change the recovery target. - Confirm the selected pods' summaries report successful moves or an already-correct pointer. An unselected pod being skipped is not a failure. If a selected pod fails, inspect its error and preview again before retrying that pod. A failed run can have moved other pods already.
For a read-only inspection, use the same workflow on main with
operation=show, an explicit channel and the intended pods. The output
identifies the current version and build and verifies its candidate. Candidate
artifact names (v3-candidate-<run id>-<run attempt>) and the candidate
workflow output also identify a build. Step 1's summary alone does not print
BUILD_ID.
Merging a Release Please release pull request automatically dispatches Step 1
from its release tag with dryRun=false; there is no separate manual Step 1
start to withhold. To stop that release, cancel its running Step 1 and any
running candidate-upload or pointer-promotion workflows. Check for a child
candidate run even if its dispatch reply was lost. Do not start or re-run
Steps 1, 2 or 3 for that release while recovering.
After those runs have stopped, preview v3-shadow-promote.yml on main with
operation=rollback-all, the target version, pods=all-production,
dry_run=true, allow_downgrade=true, allow_rebuild=false and
allow_upgrade=false. channel is ignored. As above, resolve the build in
the first preview and pin build_id explicitly in every live dispatch.
Repeat with dry_run=false, then preview and apply separately for pods=qa.
rollback-all moves v3-staging first, then ga and the release-order
channels. A channel already on an older version is left alone, not upgraded.
Conditional writes and a final read detect a racing promotion but cannot
prevent every race: if a newer version or a conflicting build remains, stop
that promoter and preview/run the rollback again. Selected pods proceed
independently even when another pod fails.
- Undo one channel's rollback: preview and apply
operation=rollbackonmainfor that channel with the intended newerversionand explicitbuild_id,allow_upgrade=true,allow_downgrade=false, andallow_rebuild=falseunless a same-version build replacement is intended.promote-gamoves all release-order channels andga, so it can undo other intentional rollbacks as well. - Direct pointer rebuild (release index unchanged): preview and apply
rollback(orrollback-all) with the sameversion, a different verifiedbuild_id, andallow_rebuild=true. These operations do not writereleases/<version>.json. A later blank-build rollback can therefore resolve to the old indexed build. Keep using explicit builds until reconciled. - Canonical rebuild: after verifying the replacement candidate, preview
and apply
stagewith itsversion, explicitbuild_idandallow_rebuild=true. Then preview and applypromote-release-orderfor each intended release-order channel, orpromote-gafor all release-order channels plusga, with the same version andallow_rebuild=true. Promotions read the staged candidate. Repeat for each required pod selection and inspect the release-index result and channel summaries. Only stage and promotion operations update the version's release index; a rebuild can replace it. Use this broader path only when those channel moves are intended.
A single-channel rollback does not move v3-staging unless that is the channel
selected. Step 2 promotes its staged candidate to one release-order channel;
Step 3 promotes it to all release-order channels and ga. A re-run can undo
a deliberate single-channel rollback. Their promoter re-checks staging and
branch tips before each write, but it is not a permanent rollback lock.
Do not use Step 1 as a rollback tool. Re-running it for an old tag normally
fails the v3-staging Git fast-forward guard before the S3 downgrade guard.
An eligible newer Step 1 can stage a newer candidate again. Stop the release
work before rollback-all, and resume only with the intended recovery plan.
Run v3-shadow-promote.yml from main with operation=status, first for
pods=all-production and separately for pods=qa. It writes nothing and
verifies every selected channel's candidate. For a single-channel rollback,
inspect that channel's version/build in the output. After rollback-all,
leave version and build_id blank and confirm no channel is newer than the
target and every channel at the target has the intended build. Requiring the
target version on every channel would wrongly fail channels deliberately
left on an older release. When every channel should match one release, a
status run with version and build_id set enforces that stronger check.
The pointer move does not immediately clear downstream caches. Allow for cache refresh and CDN/browser caching, verify the delivered SDK as well as the workflow result, and contact mParticle support for CDN invalidation.
Rollback does not move npm next, change a Git tag or GitHub Release, rewind
the Release Please manifest, or lower the next release version. Leave the
tag/release in place and never reuse a published npm version. Retagging
next is not part of this rollback procedure: core plus every published
V3 kit must remain in lockstep, followed by a full strict npm audit. Moving
only core or the affected kits blocks the next release's completeness check.
If publication stopped part-way, finish the incomplete-release recovery below
before rolling forward to a new fix version.
- Run the last V3 release cut by semantic-release with the three steps below,
Step 1 from
v3-staging. Its Step 3 bringsmainlevel withv3-development, and with it V3 Release Please, which does nothing whileV3_RELEASE_PLEASE_ENABLEDis set tofalse. - Lock
v3-developmentwith its ruleset, and retarget its open pull requests tomain. From here on, V3 pull requests merge tomain. - Before
V3_RELEASE_PLEASE_ENABLEDis set, merge one small pull request tomainthat sets.release-please-manifest.jsonandCHANGELOG.mdto that release's version. The manifest reads that version. The changelog gains a# Changelogtitle, and each semantic-release# [3.X.0]heading becomes## [3.X.0]. Release Please adds each entry before the first##or###version heading, so without this its first entry would land below that release's. - Set
V3_RELEASE_PLEASE_ENABLEDtotrue. - Set
V3_DIST_GUARD_ENABLEDonce the first release pull request's bundle commit shows as Verified, as described above.
-
The release pull request merged, but no release or tag appeared. Re-run the failed V3 Release Please run. If it fails again, publish the release from your own machine with the same files, then run Step 1 from the new tag. The command pins release-please 17.6.0, the version that the workflow's pinned
googleapis/release-please-actionv5.0.0 locks. Change both pins together. ForGITHUB_TOKEN, create a fine-grained personal access token for this repository only, with a one-day expiry. Give it write access to Contents, Pull requests and Issues, and nothing else (GitHub adds read-only Metadata). Release Please labels the release pull request through the Issues API. Delete the token once the release is published.npx release-please@17.6.0 github-release --token "$GITHUB_TOKEN" \ --repo-url mParticle/mparticle-web-sdk --target-branch main \ --config-file release-please-config.json \ --manifest-file .release-please-manifest.json -
Abandon a release. Before the merge, close the release pull request. Release Please opens a new one on the next push to
main, with every unreleased change. To pause Release Please, setV3_RELEASE_PLEASE_ENABLEDtofalsefirst, then close the open release pull request. That pauses V3 releases. It does not bring back the semantic-release path (see Fall back to the semantic-release path). Don't use theautorelease: snoozelabel. Withalways-update, Release Please keeps force-updating a snoozed PR. After the merge, if a release must not ship, cancel the in-progress V3 Release - Step 1 run if it is still running, do not run Steps 2 or 3 for that tag, and do not re-dispatch Step 1 for it. Leave the tag and the GitHub release in place, never reuse the version, and merge the fix tomain. Release Please then cuts the next version, and Step 1 from that tag movesv3-stagingpast the abandoned one. This roll-forward is how to replace a bad release. -
Release a chosen version. Add the footer
Release-As: 3.X.Yto the commit message of a pull request merged tomain, for example by editing the squash commit message. The next release pull request then proposes 3.X.Y instead of the version the commit types give.
Fall back only when Release Please itself cannot cut releases. To replace one bad release, roll forward as Abandon a release describes.
Setting V3_RELEASE_PLEASE_ENABLED to false does not bring back the old
path on its own. Step 1 from v3-staging builds whatever v3-development
holds, and v3-development stops moving at the switch.
It is safe to fall back only when no release is part-way. Every tag Release Please cut has finished Step 3 or was abandoned, and no Step 1, 2 or 3 run is in progress. Then:
-
Set
V3_RELEASE_PLEASE_ENABLEDtofalsefirst, then close the open release pull request without merging it. -
Unset
V3_DIST_GUARD_ENABLED. Remove V3 bundles change only in release PRs and V3 release bundles match version from the required checks onmain. The old Step 3 pushes each release tomaindirectly, not through a pull request. -
Lift the ruleset that locks
v3-development. Then bringv3-developmentandv3-stagingup tomain. If either ancestor check fails, stop: that branch holds a commitmainlacks. Merge it intomainwith a pull request, then repeat this step. The push is not forced, so it only fast-forwards.git fetch origin main v3-development v3-staging git merge-base --is-ancestor origin/v3-development origin/main git merge-base --is-ancestor origin/v3-staging origin/main git push --atomic origin origin/main:refs/heads/v3-development \ origin/main:refs/heads/v3-staging
-
Point both Dependabot updates in
.github/dependabot.ymlback atv3-development, and merge V3 pull requests there again. From here on, only Step 3 movesmain. -
Release with the three steps below, Step 1 from
v3-staging. Step 1 and semantic-release take the newestv3.X.Ytag reachable fromv3-staging, a Release Please tag included, so the next version follows it.
Step 3 cannot push an older v3-development over a newer main. Without
Release Please it pushes all five branches, main included. Before the push
it checks that each one can fast-forward to the tag. If one cannot, it stops
with origin/main cannot fast-forward to v3.X.Y and pushes nothing. That
means a commit reached main outside Step 3. Merge main into
v3-development with a pull request, then run Step 1 again.
To return to Release Please, finish the last release's Step 3, so main and
v3-development are the same commit. Then merge one pull request to main
that sets .release-please-manifest.json and CHANGELOG.md to that release's
version, as step 3 of Switch to Release Please describes, and points
Dependabot back at main. Set V3_RELEASE_PLEASE_ENABLED to true, and merge
V3 pull requests to main again. Set V3_DIST_GUARD_ENABLED again as
described above.
In GitHub Actions, choose the version's branch from the Use workflow from dropdown and run its workflows in order:
- Step 1: Prepare CDN Pre-Release, Publish NPM: run
V2 Release - Step 1 (
staging-step-1.yml) fromstaging, or V3 Release - Step 1 (v3-release-step-1.yml) from the V3 release tag (see the section above; before Release Please, fromv3-staging). Fromstagingorv3-staging, this workflow builds and tests the version, creates and merges a generated release branch, runs semantic-release, and publishes the npm release. V2 publishes core to npmlatest; V3 publishes core and kits to npmnext. The kit checks and recovery below apply only to V3. Before a new v3 release can advance, every existing kitnexttag must match the core SDK's currentnextversion. The one-time3.0.0bootstrap permits all kit tags to be absent so the first synchronized release can establish them. After building the target version, Step 1 also packs and registry-preflights all kit artifacts before publishing core. It then checks out the immutable release tag, waits up to five minutes for core to become visible on npm, publishes all packages inkits/publish-matrix.jsonconcurrently with a bounded worker pool, and runsauditRemotePackagesat the end ofpublish-kits.js, reusing the tarballs it already packed. On release tags that includec28064ee, a package npm has not confirmed within five minutes warns in the log and step summary, without failing Publish V3 kits (publish-kits). Tags with the integrated audit but withoutc28064ee, includingv3.34.3, fail on an unconfirmed package. A different artifact or a conflicting dist-tag fails in either case, beforeadvance-stagingmovesv3-staging. In V3 Release - Step 1, npm is then checked a second time by the release gate in Upload and stage V3 candidate described below:check-release-parity.tscompares every package'sdist.integritywith the candidate and reads npm again for up to 10 minutes before it fails the release. The gate does not read dist-tags:npm publish --tagsets them,assertDistTagWillNotMoveBackwardguards them before each publish,auditRemotePackageschecks them at the end ofpublish-kits.js, and the next release's--preflight-tagsrefuses to start until every kit's tag matches core's. An absent or older stable dist-tag is treated as propagation lag and warns; a newer or otherwise conflicting tag fails. The staging gate does not catch a tag still lagging after that warning. Confirm warned tags withnpm view <package> dist-tags.next --prefer-online, or use the standalone strict audit; otherwise the next release's preflight catches them. The five-minute post-publish audit window is unchanged. It could be shortened now that package visibility is gated again before staging, but a shorter window also reduces the chance to detect a tag conflict in this run. The standalone Audit V3 kits on npm entrypoint (publish-kits.js --audit) warns when npm has not confirmed a package yet and fails on a mismatched artifact or dist-tag (or fails on both when called with--strict), and stays callable for standalone checks. The next Step 1 refuses to start until every kit'snextmatches core, so a kit that never appears blocks the next release rather than shipping unnoticed. A rerun skips an existing kit only when its artifact is identical.dryRun=truepreviews the merge and semantic-release result without creating a branch or publishing;dryRun=falsecreates/pushes the release branch and publishes. If core publishes but kit publication (or candidate upload/stage) cannot finish, recovery depends on the Step 1 mode: in tag mode (Release Please, dispatched fromv3.X.Y), use Re-run failed jobs on the original V3 Release - Step 1 run (which keeps the original packaged candidate and its${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}build ID). Do not use Re-run all jobs. For the one exception that calls for a fresh Step 1 run, see When a kit never reaches npm. If kits andv3-stagingalready succeeded and only candidate upload or stage failed, dispatch V3 shadow release: upload candidate (v3-shadow-candidate.yml) onmainwithstep1_run_idset to the original Step 1 run ID,release_gate=true, andrelease_tagset to the release tag (v3.X.Y). In branch mode (dispatched fromv3-stagingbefore Release Please), rerun V3 Release - Step 1 fromv3-stagingwithdryRun=falseandresumeKitReleaseTagset to the exact Step 1 tag. Branch-mode recovery validates that immutable tag, resumes kits without republishing core, and runs the integrated npm audit from that tag. A green publish or recovery job alone is not proof that the candidate can stage. Because a branch-moderesumeKitReleaseTagrecovery run skips Perform Release, Package and Upload, once it finishes green dispatch V3 shadow release: upload candidate (v3-shadow-candidate.yml) onmainwithrelease_gate=trueandstep1_run_idset to the original Step 1 run. - Step 2: Publish SDK Release to Release Order Branch (optional): run
V2 Release - Step 2 (
staging-step-2.yml) frommasterfor v2, or V3 Release - Step 2 (v3-release-step-2.yml) frommainfor v3. Every run, dry runs included, rejects the other version's tag and a dispatch from any other branch. ForreleaseTag, enter the exact Git tag created by the successful Step 1 run (for example,v2.80.0orv3.0.1). Chooserelease-order-a,-b, or-casreleaseOrderBranch. For v3, that logical choice maps to the correspondingv3-release-order-*branch.dryRun=truevalidates the exact candidate and fast-forward without pushing;dryRun=falsepromotes it. - Step 3: Release to CDN and Synchronize Branches: run
V2 Release - Step 3 (
staging-step-3.yml) frommasterfor v2, or V3 Release - Step 3 (v3-release-step-3.yml) frommainfor v3, with the same rule as Step 2. ForreleaseTag, enter the same exact Git tag created by the successful Step 1 run. The workflow verifies that the tag matchespackage.json, resolves to the version's current staging head, and can fast-forward every destination. It then uses one atomic push, so either every ref updates or none does. For v2, and for v3 before Release Please, that push synchronizes the version's development branch, trunk (masterormain), and all three release-order branches. OnceV3_RELEASE_PLEASE_ENABLEDistrue, V3 Step 3 first checks that the tag is onmain, then pushes only the three release-order branches, becausemainalready holds the release andv3-developmentis retired.dryRun=trueperforms all validation without pushing.dryRun=falseperforms the atomic push and releases the candidate to those destinations. When the repository variableV3_RELEASE_ORDER_BRANCHES_RETIREDis alsotrue, the threev3-release-order-*git branches are retired: V3 Step 3 makes the same checks and pushes no branch, and V3 Step 2 stops at its first step. Every V3 channel is served from its S3 pointer, so the S3 promote that follows Step 3 still moves all release-order channels andga; it then checks thatv3-stagingis still at the tag in place of the three branches. To move one release-order channel, runpromote-release-orderby hand (see Undo a rollback or replace a build). The variable needsV3_RELEASE_PLEASE_ENABLEDto betrue; without it Step 3 fails before any push. LikeV3_RELEASE_PLEASE_ENABLED, don't change it while a Step 3 run or its S3 promote is in progress. Setting it back tofalserestores the branch pushes on the next Step 3 run, as long as the three branches still exist and can fast-forward to the tag.
Safe sequence: run Step 1 with dryRun=true, then Step 1 with dryRun=false;
copy its release tag; optionally preview and run Step 2 for each needed
release-order branch; finally run Step 3 with dryRun=true, then
dryRun=false.
V3 candidate packaging, upload, and staging: a real V3 Release - Step 1
(v3-release-step-1.yml, dryRun=false) runs Package V3 candidate
(shadow) after the release to package the release tag's committed bundles
into a v3-candidate-<run id>-<run attempt> artifact (kept for 7 days). Once
Publish V3 kits has also succeeded, it runs
Upload and stage V3 candidate, which dispatches V3 shadow
release: upload candidate (v3-shadow-candidate.yml) on main with
release_gate=true and waits up to 120 minutes (the child jobs' 110-minute
ceiling plus 10 minutes of queue time, inside a 130-minute job timeout) for it
to succeed. A failed read of the child run's status (a 5xx or rate-limit reply)
is retried until that deadline. If the job fails, times out or is cancelled
before the child run completes, it cancels the child run. A refused cancel (a
5xx or rate-limit reply) is retried with a doubling backoff (6 tries, 5 seconds
apart at first) until GitHub accepts it or the child run reads completed, first
by the wait step and then by the cleanup step. Release-gate dispatches for one
Step 1 run share one concurrency group (v3-shadow-candidate-gate-STEP1_RUN_ID),
so a re-run's child queues behind a leftover child instead of staging the same
build in parallel with it. A newer gate dispatch for the same Step 1 run takes
the group's single pending slot from an older pending one, which then fails its
own Step 1 wait. A manual dispatch with release_gate=false or a transition
workflow_run runs in another group, so it cannot displace a pending gate run.
If the dispatch request succeeds but its reply is lost or carries no
workflow_run_id, the job fails with no child run ID, so nothing cancels that
child. Before re-running Step 1, open the V3 shadow release: upload
candidate runs, find any run dispatched after the failed Step 1 run started,
and cancel it if it is still running. If it is missed, the shared concurrency
group still makes the re-run's child wait for it to finish.
Release-gate mode accepts both an in-progress v3-release-step-1.yml
parent run and one that has already
completed without being cancelled (so a maintainer can also dispatch
v3-shadow-candidate.yml manually with release_gate=true for repair after
Step 1 finishes), provided Perform Release and Package V3 candidate
(shadow) succeeded and one unexpired candidate artifact exists. Release-gate
mode also requires npm parity to pass: every package must be on npm with the
candidate's integrity. npm can take minutes to show a version it has
accepted, so while npm parity reads pending (a version npm does not show yet) or unavailable
(an npm view error or an unexpected reply), the candidate workflow reads npm
again with a doubling backoff (15 seconds at first, at most 2 minutes apart)
for up to 10 minutes, with a last read when the 10 minutes run out. A fail
reading (a published package with another integrity) fails the gate at once,
and a read stops at the first package that differs. A package still pending
or unavailable after the last read fails the gate instead of uploading. Each
npm view gets at most 30 seconds, and each read of every package at most 2
minutes. A package the read has no time left for reads unavailable. If sleep
fails between reads, the check fails instead of reading npm again at once. A
transition workflow_run, or a manual dispatch with release_gate=false,
reads npm once. The Check the candidate against the release job's
25-minute timeout covers the 10 minutes, a last read of at most 2 minutes and
its other checks.
A failure in packaging, candidate verification, S3
upload, or v3-staging pointer staging fails the Step 1 release. In
release-gate mode, V3_SHADOW_PODS must include all five production pods
(us1, us2, st1, eu1, au1); qa is optional (if qa is listed in
V3_SHADOW_PODS, it runs in the same matrix and blocks the release on failure;
if qa is omitted from V3_SHADOW_PODS, only the five
production pods block the release and qa can run separately). Stage moves each
pod's v3-staging pointer independently in parallel, so if one pod fails, the
other pods have already moved to the new candidate; re-running failed jobs on
Step 1 (within the 7-day artifact window) re-runs Upload and stage V3
candidate, dispatches the candidate workflow again, and repairs the remaining
pods so every pod converges (resumeKitReleaseTag skips packaging and upload
as before). V2's staging-step-1.yml does not package, upload, or stage V3
candidates.
A real v3 Step 1 run can publish core and create the GitHub Release before all 33 kits finish. If the kit job fails or reports an unconfirmed package:
- Do not start a newer release or run Step 2 or Step 3.
- Copy the exact release tag from the original Step 1 run.
- Use the npm kit publish summary to identify missing or rejected kits. Correct their npm or trusted-publisher configuration.
- For a Release Please release (dispatched from a
v3.X.Ytag), use Re-run failed jobs on the original V3 Release - Step 1 run (which keeps the successful package job and its${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}build ID). Do not use Re-run all jobs. If Publish V3 kits passed but a package never reached npm, follow the same-tag dispatch exception before any pod has staged. In branch mode, dispatch V3 Release - Step 1 fromv3-stagingwithdryRun=falseandresumeKitReleaseTagset to the original run's exact tag. - Wait for recovery to publish any missing kits (existing byte-identical
packages are skipped) and for
publish-kits.jsto check core and all 33 kits at that version onnext. Recovery runs the script from the immutable release tag. On tags with the integrated audit but withoutc28064ee, includingv3.34.3, a package still unconfirmed after five minutes fails Publish V3 kits. On tags with the change, it warns instead. Mismatched artifacts or conflicting dist-tags fail in both cases. Follow up on warned tags as described above: the staging gate checks integrity, not tags. - If recovering the original Release Please run, Re-run failed jobs can
re-run
advance-stagingandupload-v3-candidateusing the original run's packaged candidate (or, ifv3-stagingalready moved and only candidate upload or stage failed, dispatch V3 shadow release: upload candidate (v3-shadow-candidate.yml) onmainwithstep1_run_idset to the original Step 1 run's ID,release_gate=true, andrelease_tagset to the release tagv3.X.Ywithin the candidate's 7-day retention window). For a fresh same-tag dispatch, wait for Upload and stage V3 candidate on the new Step 1 run. Do not reuse the original run ID or artifact. In branch mode, theresumeKitReleaseTagrecovery run skips packaging and upload. Dispatch V3 shadow release: upload candidate (v3-shadow-candidate.yml) onmainwithstep1_run_idset to the original Step 1 run's ID andrelease_gate=true, within the candidate's 7 days. - Continue to Step 2 or Step 3 only after recovery, candidate upload and staging have passed.
In tag mode, v3-staging moves to the release tag before the S3 upload and
stage runs. If v3-staging moves and the S3 upload or stage then fails,
recover by using Re-run failed jobs on the original V3 Release - Step 1
run (which preserves the successful package job and its
${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT} build ID) or by dispatching V3
shadow release: upload candidate (v3-shadow-candidate.yml) on main with
step1_run_id set to the original Step 1 run's ID, release_gate=true, and
release_tag set to the release tag (v3.X.Y),
within the candidate's 7-day artifact retention window. Never start a fresh
Step 1 run or use Re-run all jobs for recovery after any pod has staged:
that packages a new ${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT} build ID, and
promote-v3-release.ts rejects a different build of the same version on
already-staged pods without --allow-rebuild. When release_tag is omitted on
a tag-origin run (for example, when re-running failed jobs on an earlier
release tag whose v3-release-step-1.yml predates release_tag),
shadow-release-trigger.ts reads the release tag from the Step 1 run's
head_branch, logs a warning that the caller predates release_tag, and
continues; the check fails only when release_tag is provided and differs from
head_branch. Any rollback of this change on main must keep the
release_tag input declaration on v3-shadow-candidate.yml so Step 1 runs
from newer tags that send inputs[release_tag] can still dispatch the workflow
without GitHub rejecting release_tag as an unexpected input.
In tag mode, advance-staging waits for Confirm v3 staging release state,
Perform Release, Package V3 candidate (shadow) and Publish V3 kits.
It does not wait for the npm gate in Upload and stage V3 candidate. If npm
still does not show a package after the gate's 10-minute retry window and final
check, v3-staging is already at the release tag, but the candidate is not
uploaded or staged.
Once npm view shows every package at the release version, use Re-run failed
jobs on the original Step 1 run within the candidate's 7-day artifact window.
The gate runs again with the same build ID.
If Publish V3 kits passed with a warning, Re-run failed jobs can retry the gate but cannot publish a missing kit. Correct the package's npm or trusted-publisher setup first. Confirm that the original candidate workflow is not running and that no pod has staged this release.
In tag mode, dispatch V3 Release - Step 1 again from the same v3.X.Y tag
with dryRun=false. A tag run refuses resumeKitReleaseTag. Step 1 refuses
v3-staging while V3_RELEASE_PLEASE_ENABLED is true. If the same-tag npm
preflight passes, the new run skips byte-identical packages, publishes missing
kits, and packages, gates and stages a new build ID. If preflight fails, stop
and reconcile the reported npm tags before retrying. If any pod has staged the
release, do not dispatch Step 1 again.
If recovery reports that the tagged core version is missing from npm, stop the kit recovery. Semantic-release may have pushed the generated staging commit and tag before core publication failed:
- Wait for npm propagation and confirm whether the tagged core version exists.
- If core appears, rerun the kit recovery above with the same tag.
- If core is confirmed absent, use the controlled maintainer procedure to
restore
v3-stagingto the parent of the generated release commit and delete the automation-created orphan tag. - Rerun a normal Step 1 release with
resumeKitReleaseTagempty.
Do not delete or move the tag until npm absence is confirmed. An npm publish that times out locally can still succeed in the registry.
If core's next tag changes without a corresponding Step 1 Git tag, do not use
the bootstrap exception or guess a recovery tag. Stop releases and reconcile
the unexpected npm and Git state before continuing.
Each version's trunk owns its own copy of its release workflows: master for
v2 and main for v3. A change to one version's release steps does not need a
twin on the other trunk. Steps 2 and 3 run from the dispatching trunk, and the
rule above keeps each version on its own trunk's copy. GitHub executes Step 1
from the branch selected in the Use workflow from dropdown, so every
dryRun=false Step 1 run rejects the release unless its workflow on the
staging branch is identical to its trunk's copy: staging-step-1.yml on
staging to master's, and v3-release-step-1.yml on v3-staging to
main's. A V3 Step 1 run from a release tag requires the tag's commit to be on main
instead, so a later edit to the workflow on main does not block an earlier
tag.
npm trusted publishing names the workflow file that publishes each package:
staging-step-1.yml publishes v2 of @mparticle/web-sdk, and
v3-release-step-1.yml publishes v3 of @mparticle/web-sdk and every kit in
kits/publish-matrix.json. The V2 workflow keeps the staging-step-1.yml
filename so its trusted-publisher configuration does not need to change.
The mParticle Web SDK is available under the Apache License, Version 2.0. See the LICENSE file for more info.
This project is tested with BrowserStack