Script tag

For websites without npm: Webflow, Framer, WordPress, Shopify or plain HTML. One line in the <head> of every page:

<script async src="https://app.mrrocket.dev/sdk.js" data-key="mrr_pub_…"></script>

Settings › Products › your product (the tracking code) shows this line with your product's key filled in, and a Copy button.

Site builderWhere it goes
WebflowSite settings › Custom code › Head
FramerSite settings › General › Custom code
WordPressThe theme's header, or a header-code plugin
Shopifytheme.liquid, before </head>

What it does on its own#

  • Page views, also when the page changes without a reload (single-page apps)
  • Clicks on anything marked data-ck-goal="signup_started" count as that goal
  • Heatmap clicks and scroll depth
  • UTM parameters, referrer and affiliate referrals (?ref=)
  • Uncaught errors, for Build › Bugs
  • Feature flags and experiments from MRRocket
  • Session recordings, only with the visitor's recording consent

Your own calls#

mrrocket.track("signup", { plan: "team" });
mrrocket.identify(user.id, { email: user.email, plan: "pro" });
mrrocket.reset(); // on sign-out
mrrocket.captureError(error);
mrrocket.setConsent("cookies"); // "cookieless" | "cookies" | "off"
mrrocket.ready(function (m) {
    if (m.getFlag("new-checkout")) showNewCheckout();
    var variant = m.getVariant("pricing-hero");
});

getFlag is false until flags have loaded; read flags inside ready().

To call mrrocket before the file has loaded, put this stub above the script tag. Calls wait in a queue and run once the SDK is there:

<script>!function(w,m){w[m]=w[m]||{q:[]};"track identify reset captureError setConsent ready".split(" ").forEach(function(k){w[m][k]=w[m][k]||function(){w[m].q.push([k,arguments])}})}(window,"mrrocket");</script>

Settings#

Data attributes on the script tag:

AttributeWhatDefault
data-keyYour product's public keyrequired
data-api-hostWhere MRRocket runswhere sdk.js came from
data-consentcookieless, cookies or off, as in consent modescookieless
data-replaytrue once the visitor agreed to session recordingsoff
data-respect-dntSend nothing under Do Not Track or Global Privacy Controloff
data-heatmaps, data-errorsfalse turns them offon
data-releaseYour release name, for Build › Bugsnone

A/B tests on texts#

Mark an element with data-ck-text. MRRocket replaces its text with the visitor's variant; the text in your page is the control.

<h1 data-ck-text="hero-title">Grow your SaaS</h1>
The <Text> and <Experiment> components are for Next.js only. On a script-tag site, experiments change texts marked data-ck-text.

Redirects and redirect tests#

A page redirect (Convert › Landing pages › Redirect…) and a redirect test (Tests, "Whole page") need nothing on your site: the script sends the visitor on as soon as it knows where, keeping the address's UTM parameters. See redirect tests.

The script loads after your page, so the old page can flash for a moment. To hide the page until the script decided, add this before the script tag. It shows the page after one second whatever happens:

<style>.ck-hide{opacity:0!important}</style>
<script>document.documentElement.classList.add("ck-hide");setTimeout(function(){document.documentElement.classList.remove("ck-hide")},1000)</script>

The snippet also stops texts of data-ck-text tests from flickering.

Push notifications#

mrrocket.push.subscribe() from a button signs the signed-in visitor's browser up for your journeys' push steps; your site hosts /mrrocket-sw.js. See Push notifications.

Session recordings#

When your product records sessions and the visitor agreed (data-replay="true", or mrrocket.setConsent({ replay: true }) from your consent banner), the recorder loads as a second file. Pages that do not record never load it. Inputs are masked and payment fields never recorded, as in the Next.js SDK.

sdk.js is about 8 KB compressed. New releases reach every site within an hour.