> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mention-me.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dashboard Tag

> Add the referrer dashboard to your customer account area so referrers can track their referral status

export const SignInNotice = ({message = "To see code snippets pre-filled with your partner code"}) => {
  return <div data-mm-sign-in style={{
    display: "none"
  }}>
      <Info>
        {message}, <a data-mm-sign-in-link href="https://app.mention-me.com/sign-in"><strong>sign in</strong></a>.
      </Info>
    </div>;
};

export const MerchantContext = () => {
  const PARTNER_STORAGE_KEY = "mm-docs-partner";
  const escapeHtml = str => str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
  const getStoredPartner = () => {
    try {
      const raw = localStorage.getItem(PARTNER_STORAGE_KEY);
      if (!raw) return null;
      const data = JSON.parse(raw);
      if (data && data.partnerCode) return data;
    } catch (e) {}
    return null;
  };
  const setStoredPartner = data => {
    try {
      localStorage.setItem(PARTNER_STORAGE_KEY, JSON.stringify(data));
    } catch (e) {}
  };
  const clearStoredPartner = () => {
    try {
      localStorage.removeItem(PARTNER_STORAGE_KEY);
    } catch (e) {}
  };
  const captureQueryParams = () => {
    const params = new URLSearchParams(window.location.search);
    const partner = params.get("partner");
    const name = params.get("name");
    if (partner) {
      const data = {
        partnerCode: partner
      };
      if (name) data.displayName = name;
      setStoredPartner(data);
      params.delete("partner");
      params.delete("name");
      const qs = params.toString();
      const clean = window.location.pathname + (qs ? "?" + qs : "") + window.location.hash;
      window.history.replaceState(null, "", clean);
      return data;
    }
    return getStoredPartner();
  };
  const isLocal = typeof window !== "undefined" && window.location.hostname === "localhost";
  const API_BASE = isLocal ? "http://localhost:3001" : "https://app.mention-me.com";
  const SIGN_IN_BASE = isLocal ? "http://localhost:3001/sign-in" : "https://app.mention-me.com/sign-in";
  const MERCHANT_WINDOW_KEY = "__mmMerchantContext";
  const publishMerchant = data => {
    window[MERCHANT_WINDOW_KEY] = data;
    window.dispatchEvent(new CustomEvent("mm-merchant-ready", {
      detail: data
    }));
  };
  const clearMerchant = () => {
    delete window[MERCHANT_WINDOW_KEY];
  };
  const BADGE_ID = "mm-partner-badge";
  const showPartnerBadge = (partnerData, source) => {
    if (document.getElementById(BADGE_ID)) return;
    const nav = document.getElementById("navigation-items");
    if (!nav || !nav.parentNode) return;
    const badge = document.createElement("div");
    badge.id = BADGE_ID;
    badge.className = "mm-partner-badge";
    const hasName = partnerData.displayName && partnerData.displayName !== partnerData.partnerCode;
    const heading = hasName ? escapeHtml(partnerData.displayName) : escapeHtml(partnerData.partnerCode);
    const code = hasName ? escapeHtml(partnerData.partnerCode) : "";
    const codeStr = code ? ' <span class="mm-partner-badge-code">' + code + '</span>' : '';
    const resetTitle = source === "clerk" ? "Sign out and switch account" : "Clear personalisation";
    badge.innerHTML = '<div class="mm-partner-badge-inner">' + '<span class="mm-partner-badge-content">' + '<span class="mm-partner-badge-context">Personalised for </span>' + '<span class="mm-partner-badge-name">' + heading + '</span>' + codeStr + '</span>' + '<button class="mm-partner-badge-reset" title="' + resetTitle + '">&times;</button>' + '</div>';
    nav.parentNode.insertBefore(badge, nav);
    badge.querySelector(".mm-partner-badge-reset").addEventListener("click", e => {
      e.preventDefault();
      e.stopPropagation();
      if (source === "clerk" && window.Clerk && window.Clerk.signOut) {
        clearMerchant();
        const redirect = SIGN_IN_BASE + "?redirect_url=" + encodeURIComponent(window.location.href);
        window.Clerk.signOut().then(() => {
          window.location.href = redirect;
        }).catch(() => {
          window.location.reload();
        });
        return;
      }
      clearStoredPartner();
      window.location.reload();
    });
  };
  const removePartnerBadge = () => {
    const el = document.getElementById(BADGE_ID);
    if (el) el.remove();
  };
  const showNotices = () => {
    document.querySelectorAll("[data-mm-sign-in]").forEach(el => {
      el.style.display = "";
    });
    const redirect = SIGN_IN_BASE + "?redirect_url=" + encodeURIComponent(window.location.href);
    document.querySelectorAll("[data-mm-sign-in-link]").forEach(a => {
      a.href = redirect;
    });
  };
  const hideNotices = () => {
    document.querySelectorAll("[data-mm-sign-in]").forEach(el => {
      el.style.display = "none";
    });
  };
  const walkCodeBlocks = replacements => {
    document.querySelectorAll("pre code").forEach(codeEl => {
      let html = codeEl.innerHTML;
      if (replacements) {
        for (const [from, to] of replacements) {
          html = html.split(from).join(escapeHtml(to));
        }
      }
      const paramStyle = "color:inherit;filter:brightness(110%);font-weight:bold;text-decoration:underline;cursor:pointer";
      html = html.replace(/(\?|&amp;)([a-z_]+)=/g, (match, prefix, name) => {
        const slug = name.replace(/_/g, "-");
        const target = document.getElementById("param-" + slug);
        if (!target) return match;
        return prefix + '<a href="#param-' + slug + '" style="' + paramStyle + '">' + name + "</a>=";
      });
      codeEl.innerHTML = html;
    });
  };
  const observeTabSwitches = callback => {
    let processing = false;
    const observer = new MutationObserver(() => {
      if (processing) return;
      processing = true;
      setTimeout(() => {
        callback();
        processing = false;
      }, 50);
    });
    setTimeout(() => {
      const tabs = document.querySelector("[role='tablist']");
      if (tabs && tabs.parentElement) {
        observer.observe(tabs.parentElement, {
          attributes: true,
          subtree: true,
          childList: true
        });
      }
    }, 500);
  };
  const pollForClerk = (onReady, onTimeout) => {
    let n = 0;
    const tick = () => {
      if (window.Clerk && window.Clerk.loaded) {
        return onReady(window.Clerk);
      }
      if (++n < 40) {
        setTimeout(tick, 250);
      } else {
        onTimeout();
      }
    };
    setTimeout(tick, 100);
  };
  const fetchMerchantFromAPI = () => {
    return fetch(API_BASE + "/api/docs/context", {
      credentials: "include",
      cache: "no-store"
    }).then(res => res.ok ? res.json() : null);
  };
  useEffect(() => {
    let cancelled = false;
    const urlPartner = captureQueryParams();
    const onPersonalised = (merchant, source) => {
      if (cancelled) return;
      const replacements = [["YOUR_PARTNER_CODE", merchant.partnerCode]];
      if (merchant.displayName) {
        replacements.push(["YOUR_TRADING_NAME", merchant.displayName]);
      }
      hideNotices();
      showPartnerBadge(merchant, source);
      walkCodeBlocks(replacements);
      observeTabSwitches(() => walkCodeBlocks(replacements));
    };
    const onUnauth = () => {
      if (cancelled) return;
      clearMerchant();
      removePartnerBadge();
      showNotices();
      walkCodeBlocks(null);
      observeTabSwitches(() => walkCodeBlocks(null));
    };
    const tryUrlFallback = () => {
      if (cancelled) return;
      if (urlPartner) {
        onPersonalised(urlPartner, "url");
      } else {
        onUnauth();
      }
    };
    if (!document.cookie.includes("__client_uat")) {
      tryUrlFallback();
      return;
    }
    pollForClerk(clerk => {
      if (cancelled) return;
      if (!clerk.session) {
        tryUrlFallback();
        return;
      }
      fetchMerchantFromAPI().then(data => {
        if (data) {
          publishMerchant(data);
          onPersonalised(data, "clerk");
        } else {
          tryUrlFallback();
        }
      }).catch(() => tryUrlFallback());
    }, () => {
      if (!cancelled) tryUrlFallback();
    });
    return () => {
      cancelled = true;
    };
  }, []);
  return null;
};

<MerchantContext />

## Overview

The dashboard tag lets referrers check their referral status, see pending rewards, and share with more friends. Place it in your customer account area.

## Integration

<Steps>
  <Step title="Add the wrapper div">
    ```html theme={null}
    <div id="mmWrapper"></div>
    ```
  </Step>

  <Step title="Add the JavaScript tag">
    <SignInNotice />

    <Tabs>
      <Tab title="Embedded (default)">
        <CodeGroup>
          ```html Demo theme={null}
          <!-- Begin Mention Me dashboard integration -->
          <script type="text/javascript"
            src="https://tag-demo.mention-me.com/api/v2/dashboard/YOUR_PARTNER_CODE?email=<INSERT_EMAIL>&firstname=<INSERT_FIRSTNAME>&surname=<INSERT_SURNAME>&situation=dashboard&locale=<INSERT_LOCALE>">
          </script>
          <!-- End Mention Me dashboard integration -->
          ```

          ```html Live theme={null}
          <!-- Begin Mention Me dashboard integration -->
          <script type="text/javascript"
            src="https://tag.mention-me.com/api/v2/dashboard/YOUR_PARTNER_CODE?email=<INSERT_EMAIL>&firstname=<INSERT_FIRSTNAME>&surname=<INSERT_SURNAME>&situation=dashboard&locale=<INSERT_LOCALE>">
          </script>
          <!-- End Mention Me dashboard integration -->
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Link">
        Renders a link that opens the dashboard in an overlay.

        <CodeGroup>
          ```html Demo theme={null}
          <!-- Begin Mention Me dashboard integration -->
          <script type="text/javascript"
            src="https://tag-demo.mention-me.com/api/v2/dashboard/YOUR_PARTNER_CODE?email=<INSERT_EMAIL>&firstname=<INSERT_FIRSTNAME>&surname=<INSERT_SURNAME>&situation=dashboard&locale=<INSERT_LOCALE>&implementation=link">
          </script>
          <!-- End Mention Me dashboard integration -->
          ```

          ```html Live theme={null}
          <!-- Begin Mention Me dashboard integration -->
          <script type="text/javascript"
            src="https://tag.mention-me.com/api/v2/dashboard/YOUR_PARTNER_CODE?email=<INSERT_EMAIL>&firstname=<INSERT_FIRSTNAME>&surname=<INSERT_SURNAME>&situation=dashboard&locale=<INSERT_LOCALE>&implementation=link">
          </script>
          <!-- End Mention Me dashboard integration -->
          ```
        </CodeGroup>
      </Tab>
    </Tabs>
  </Step>
</Steps>

## Email in the URL path

The dashboard tag also accepts an equivalent URL form where the customer's email is included as a path segment rather than a query parameter. This is the canonical dashboard URL and is useful when generating a personalised dashboard link from a server-rendered email or account page.

<CodeGroup>
  ```html Demo theme={null}
  <!-- Begin Mention Me dashboard integration (email in path) -->
  <script type="text/javascript"
    src="https://tag-demo.mention-me.com/api/v2/dashboard/YOUR_PARTNER_CODE/<INSERT_URL_ENCODED_EMAIL>?firstname=<INSERT_FIRSTNAME>&surname=<INSERT_SURNAME>&situation=dashboard&locale=<INSERT_LOCALE>">
  </script>
  <!-- End Mention Me dashboard integration -->
  ```

  ```html Live theme={null}
  <!-- Begin Mention Me dashboard integration (email in path) -->
  <script type="text/javascript"
    src="https://tag.mention-me.com/api/v2/dashboard/YOUR_PARTNER_CODE/<INSERT_URL_ENCODED_EMAIL>?firstname=<INSERT_FIRSTNAME>&surname=<INSERT_SURNAME>&situation=dashboard&locale=<INSERT_LOCALE>">
  </script>
  <!-- End Mention Me dashboard integration -->
  ```
</CodeGroup>

Make sure the email is URL encoded (for example `doreen%40example.com`). All other parameters stay as query-string arguments.

## Parameters

### Mandatory

<ResponseField name="email" type="string" required>
  Customer's email address. Example: `doreen@example.com`
</ResponseField>

<ResponseField name="firstname" type="string" required>
  Customer's first name. Example: `Doreen`
</ResponseField>

<ResponseField name="surname" type="string" required>
  Customer's last name. Example: `Green`
</ResponseField>

<ResponseField name="situation" type="string" required>
  Situation identifier. Example: `dashboard`
</ResponseField>

<ResponseField name="locale" type="string" required>
  Locale code. Example: `en_GB`
</ResponseField>

### Optional

<ResponseField name="fullname" type="string">
  Full name (alternative to firstname + surname).
</ResponseField>

<ResponseField name="customer_id" type="string">
  Your internal customer identifier.
</ResponseField>

<ResponseField name="phone_number" type="string">
  Customer's phone number.
</ResponseField>

<ResponseField name="segment" type="string">
  Customer segment.
</ResponseField>

<ResponseField name="custom_field" type="string">
  Custom data field.
</ResponseField>

<ResponseField name="key" type="string">
  Encryption key identifier.
</ResponseField>

<ResponseField name="implementation" type="string">
  Display mode: `embed` (default) or `link`.
</ResponseField>
