Install — Web
Install With a Script Tag
Add AnyReplay to any website with one script tag: what the snippet does, the commands it accepts, Google Tag Manager, and how to check it is recording.
The script tag is the fastest way to record a website. It works with any stack — server-rendered pages, WordPress, a static site, a single-page app — and it keeps the recorder out of your own bundle. Your project's setup page in the dashboard shows this snippet with your key filled in. Platform steps for Shopify, WordPress, Webflow, Framer and Wix are in integrations.
The snippet
<script>
(function (w, d) {
w.anyreplay = w.anyreplay || function () {
(w.anyreplay.q = w.anyreplay.q || []).push(arguments);
};
var s = d.createElement('script');
s.async = 1;
s.src = 'https://cdn.anyreplay.com/v1/ar.min.js?k=YOUR_PROJECT_KEY';
d.head.appendChild(s);
})(window, document);
anyreplay('init', {
projectKey: 'YOUR_PROJECT_KEY',
ingestUrl: 'https://in.anyreplay.com',
// Stop recording after this many sessions in a calendar month.
// maxSessionsPerMonth: 10000,
// Form fields are masked: what visitors type replays as asterisks.
// Passwords, one-time codes and card fields are masked either way.
// Uncomment the first line to record what visitors type, or the
// second to hide rich-text editors too.
// maskAllInputs: false,
// maskAllTyping: true
});
</script>It does three things. It defines window.anyreplay as a tiny function that queues every call; it adds an asynchronous <script> for the recorder, so page rendering is never blocked; and it queues init with your options. When the recorder arrives it replays the queue in order, so calls made before it loaded — init, track, identify, consent — are not lost.
The loader URL is https://cdn.anyreplay.com/v1/ar.min.js?k=YOUR_PROJECT_KEY. The key in its query string lets the setup page tell "the snippet is not on the page" apart from "the snippet loaded but its events are blocked", which are fixed in completely different ways. The key is public either way.
Options
The object passed to init takes every option in the browser SDK reference. The ones most sites set:
anyreplay('init', {
projectKey: 'YOUR_PROJECT_KEY',
ingestUrl: 'https://in.anyreplay.com',
sampleRate: 0.5, // record half of all visitors
requireConsent: true, // wait for anyreplay('consent', true)
maxSessionsPerMonth: 10000, // stop this project at 10,000 sessions a month
maskAllTyping: true, // hide rich-text editors too, not just form fields
});Form fields are masked by default (maskAllInputs), so a recording shows a form being filled in without what went into it. Set maskAllInputs: false to record what visitors type; passwords, one-time codes and payment fields stay masked either way, while email and telephone fields are ordinary fields and are recorded with the rest. The setup page writes maskAllInputs: false into the snippet for you if the project's masking switch is off. Rich-text editors are recorded unless you set maskAllTyping: true. Read masking and blocking before you install on a page with a form.
init runs once per page; a second init is ignored. The ingestUrl line is the default and only needs changing for a self-hosted install.
Commands
| Call | What it does |
|---|---|
anyreplay('init', options) | Starts recording, or waits for consent when requireConsent is set. |
anyreplay('track', name, properties?) | Puts a named marker on the timeline. See custom events. |
anyreplay('identify', { userId, email }) | Attaches your user id or email to the session. See identify users. |
anyreplay('consent', true) | Starts a recorder that was waiting for consent. false stops it. See consent. |
anyreplay('flush') | Sends whatever is buffered now. |
anyreplay('stop') | Stops recording for the rest of this page. |
Unknown commands are ignored rather than raising an error, so a newer snippet never breaks an older recorder a browser has cached. Nothing the recorder does throws into your page; errors are caught and logged as warnings.
Google Tag Manager
Create a tag
In Google Tag Manager choose New tag → Custom HTML and paste the snippet exactly as shown in your project.
Trigger it on every page
Set the trigger to All Pages so each page load starts or resumes the session.
Publish and test
Publish the container, load your site and watch the setup page switch to Connected. If you use a consent mode, fire the tag only after consent, or keep it on all pages with
requireConsent: trueand callanyreplay('consent', true)from your consent tag.
Check that it works
- The setup page flips to Connected after the first accepted event and shows how long the install took.
- In the browser's network panel you should see
ar.min.jsload fromcdn.anyreplay.comandPOSTrequests toin.anyreplay.com/v1/ingest/eventsanswered with202. - Add
debug: trueto the options to have the recorder log why it is not recording — sampled out, refused, stopped — in the console. - The setup page also links to a sample page wired to your project, for testing before the snippet is on a real site.
If you use a Content Security Policy, allow the two AnyReplay hosts first — see Content Security Policy.