Show Geo Campaign Modules by Visitor IP in Vue React

Autor:Lisa Farrell · 2026-06-01

Vue, React, and Next.js landing pages are well suited for regional campaign modules. After default content renders, the browser can call the IP interface and switch the banner, CTA, offer copy, or signup link by country.

API explanation

A browser-side call checks the visitor IP and returns the visitor IP, country, region, and city. It is suitable for localized content display.

{"ip":"185.220.236.7","country":"TW","region":"Taiwan","city":"Taipei"}

Use cases

These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.

  • These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.
  • Show Geo Campaign Modules by Visitor IP in Vue React
  • API explanation
  • SEO and UX recommendations

Implementation logic

Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.

  • Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
  • A browser-side call checks the visitor IP and returns the visitor IP, country, region, and city. It is suitable for localized content display.
  • All examples below use https://my.ipin.io/info directly, with localized comments and interface text.
  • Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.

Code example

All examples below use https://my.ipin.io/info directly, with localized comments and interface text.

React

import { useEffect, useState } from "react";
const defaultCampaign = { title: "Welcome. This is the default content.", url: "/signup" };
const campaignMap = { TW: { title: "Content for Taiwan visitors", url: "/tw" }, US: { title: "Content for United States visitors", url: "/us" }, JP: { title: "Content for Japan visitors", url: "/jp" } };
export default function GeoCampaign() {
  const [campaign, setCampaign] = useState(defaultCampaign);
  useEffect(() => {
    let cancelled = false;
    fetch("https://my.ipin.io/info")
      .then(res => res.json())
      .then(info => { if (!cancelled) setCampaign(campaignMap[info.country] || defaultCampaign); })
      .catch(() => { if (!cancelled) setCampaign(defaultCampaign); });
    return () => { cancelled = true; };
  }, []);
  return <a href={campaign.url}>{campaign.title}</a>;
}

Vue

<template>
  <a :href="campaign.url">{{ campaign.title }}</a>
</template>
<script>
const defaultCampaign = { title: "Welcome. This is the default content.", url: "/signup" };
const campaignMap = { TW: { title: "Content for Taiwan visitors", url: "/tw" }, US: { title: "Content for United States visitors", url: "/us" }, JP: { title: "Content for Japan visitors", url: "/jp" } };
export default {
  data() { return { campaign: defaultCampaign }; },
  mounted() {
    fetch("https://my.ipin.io/info")
      .then(res => res.json())
      .then(info => { this.campaign = campaignMap[info.country] || defaultCampaign; })
      .catch(() => { this.campaign = defaultCampaign; });
  }
};
</script>

SEO and UX recommendations

Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.

Common mistakes

The following issues affect article accuracy, code usability, and the credibility of the API explanation.

  • The following issues affect article accuracy, code usability, and the credibility of the API explanation.
  • Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.
  • Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
  • These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.

Summary

A browser-side call checks the visitor IP and returns the visitor IP, country, region, and city. It is suitable for localized content display.

FAQ

The questions below are written specifically for this article and are directly related to the implementation.

Question:Why are Vue and React suitable here?
Answer:The request comes from the visitor browser, so the response represents the visitor IP.
Question:Will the page show default content first?
Answer:Yes. That keeps the first render stable and usable.
Question:Why does React use a cancelled flag?
Answer:It prevents state updates after the component unmounts.
Question:Why should Vue not start with an empty campaign object?
Answer:An empty object can render an empty title or button on the first screen.
Question:Can this be used in Next.js?
Answer:Yes. Use it in a client component for visitor-side detection.