> ## 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.

# Homepage Promotions

> Add referral promotion placements to your homepage with cornerpeel and click-overlay options

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 />

## Why you should promote referral on your homepage

Homepage promotion is an effective method of driving acquisition. Depending on your number of monthly visitors, it could drive up to 60% of all new customer acquisition.

The most common homepage promotion methods require a [landing page](/developer-docs/integration/entry-points/landing-page) to point customers to and allow them to register and share the referral offer.

## Implementation options

There are two main ways to enable homepage promotions: via a link to the referral landing page, or via a tag.

<CardGroup cols={1}>
  <Card title="Option 1: Via a link to the referral landing page" icon="link">
    Gives you full control over your homepage assets. You can promote your referral programme via a link to the referral landing page and fully control the design, but you cannot mention specific available rewards.
  </Card>

  <Card title="Option 2: Via a tag" icon="code">
    Requires adding a simple tag to your homepage so your marketing team can customise design and copy via the Mention Me platform. Available as a homepage corner peel or a link to an overlay.
  </Card>
</CardGroup>

## How to enable homepage promotions via a landing page

<Steps>
  <Step title="Create a referral landing page">
    Ensure you've already created a referral landing page. See [landing page instructions](/developer-docs/integration/entry-points/landing-page).
  </Step>

  <Step title="Create a homepage link">
    Create a link on your homepage that points to the referral landing page. This can be in any form you like — a text link, a banner or an image. We recommend creating a dedicated banner below the header or a homepage tile.
  </Step>

  <Step title="Add a situation parameter for tracking">
    So you can track performance, add a situation parameter to the landing page link. For example:

    ```
    www.example.com/refer-a-friend?situation=homepage-promo
    ```

    If you're promoting the referral programme in multiple places on the homepage, use a unique situation for each promotion point. This will let you track each one separately.
  </Step>
</Steps>

<Info>
  If you're integrating this homepage promotion option, avoid specifying rewards or any other elements being tested in the copy. Otherwise you risk showing information that doesn't match A/B testing set up in the Mention Me platform by your marketing team.

  For example, instead of saying **"Earn £50 credit when you refer"**, use a more generic message such as **"Earn rewards by sharing with friends"**.
</Info>

## How to enable homepage promotions via a tag

<SignInNotice />

<Tabs>
  <Tab title="Corner peel">
    The corner peel is one of the best ways to promote referral on your homepage. It's easy to implement, requiring only adding a tag to the page that shows a referral overlay when clicked.

    Add the following in the body of the homepage:

    <CodeGroup>
      ```html Demo theme={null}
      <!-- Begin Mention Me referrer integration -->
      <script type="text/javascript"
        src="https://tag-demo.mention-me.com/api/v2/referreroffer/YOUR_PARTNER_CODE?situation=homepage-cornerpeel&locale=en_GB">
      </script>
      <!-- End Mention Me referrer integration -->
      ```

      ```html Live theme={null}
      <!-- Begin Mention Me referrer integration -->
      <script type="text/javascript"
        src="https://tag.mention-me.com/api/v2/referreroffer/YOUR_PARTNER_CODE?situation=homepage-cornerpeel&locale=en_GB">
      </script>
      <!-- End Mention Me referrer integration -->
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Link to an overlay">
    This option will display a link that shows the referral overlay when clicked. This has the advantage of letting customers register without leaving the homepage. The link can be customised to look like a button, and can be incorporated within a banner, image or another element on the page.

    <Steps>
      <Step title="Add the wrapper div">
        Create an empty div with the ID `mmWrapper`. This is just a placeholder which is populated via the JavaScript tag.

        ```html theme={null}
        <!-- Begin Mention Me referrer placeholder div -->
        <div id="mmWrapper"></div>
        <!-- End Mention Me referrer placeholder div -->
        ```
      </Step>

      <Step title="Add the tag">
        <CodeGroup>
          ```html Demo theme={null}
          <!-- Begin Mention Me referrer integration -->
          <script type="text/javascript"
            src="https://tag-demo.mention-me.com/api/v2/referreroffer/YOUR_PARTNER_CODE?situation=homepage-click-overlay&locale=en_GB">
          </script>
          <!-- End Mention Me referrer integration -->
          ```

          ```html Live theme={null}
          <!-- Begin Mention Me referrer integration -->
          <script type="text/javascript"
            src="https://tag.mention-me.com/api/v2/referreroffer/YOUR_PARTNER_CODE?situation=homepage-click-overlay&locale=en_GB">
          </script>
          <!-- End Mention Me referrer integration -->
          ```
        </CodeGroup>

        Mention Me will customise the link style to match the look and feel of your website. The end result will be a CTA which displays the overlay when clicked.
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Parameters

### Mandatory

<ResponseField name="situation" type="string" required>
  `homepage-cornerpeel` or `homepage-click-overlay`. Example: `homepage-cornerpeel`
</ResponseField>

### Optional

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