Capture the Ruler Analytics Visitor ID

Accessing the Ruler Analytics Visitor ID (RAID)

Accessing the Ruler Analytics Visitor ID

Ruler Analytics assigns a unique visitor ID(RAID) to each user on your website. This ID can be used to associate website activity with individual users or form submissions. We recomened capturing the RAID if you do not wish to capture or report on any PII data such as Email address.

The Raid can be used as your visitor identifier between your internal data and your Ruler reporting. It is available to capture from the website in two ways:


📘

Before Starting

Ensure you have the Main Ruler Analytics JavaScript on your website. This can be found in your account here.

Global JavaScript Variable

If the Ruler tracking tag is present on your site, the visitor ID is exposed as a global variable RulerAnalyticsVisitorId:

You can access it like this:

console.log(RulerAnalyticsVisitorId);

Cookie (__rasesh)

The visitor ID is also stored in a first-party cookie named __rasesh.

To access it in JavaScript:

function getCookie(name) {
  
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}

const rulerVisitorId = getCookie('__rasesh');
console.log(rulerVisitorId);

📘

Important Note

This value may not be available immediately on page load. The visitor ID variable and cookie will not be available until the Ruler tracking tag loads. It may also not be available if the user doesn’t accept cookies.

With any use case you should consider fallback logic if the ID is not available.

** Common Use Case**:

Add Visitor ID to a Form

To capture the visitor ID with a form submission, add it to a hidden input field:HTML:

<!--hidden form input field for Ruler visitor id-->
<input type="hidden" name="ruler_visitor_id" id="ruler_visitor_id">

document.addEventListener('DOMContentLoaded', function () {
  const visitorId = window.RulerAnalyticsVisitorId || getCookie('__rasesh');
  const input = document.getElementById('ruler_visitor_id');
  if (input && visitorId) {
    input.value = visitorId;
  }
});