訪問者カウンターAPI ドキュメント

私たちのAPIを使用すると、ウェブサイトの訪問者を追跡し、訪問者統計を無料で取得できます。APIキーなし、レート制限なし、プレミアム機能なし - シンプルで無料のAPIだけです。

はじめに

訪問者カウンターAPIを使用すると、ウェブサイトの訪問者を追跡し、訪問者統計を完全に無料で取得できます。

ベースURL

https://visitor.6developer.com

認証 - APIキー不要

基本的な使用には認証は必要ありません。ドメインが識別子として使用されます。私たちのAPIには使用制限はありません。

APIエンドポイント

訪問を記録する

POST
/visit

ウェブサイトへの訪問を記録します。

リクエストボディ

{
  "domain": "example.com",
  "timezone": "America/New_York", // Optional, defaults to UTC
  "page_path": "/blog/my-article", // Optional, the path of the current page
  "page_title": "My Article Title", // Optional, the title of the current page
  "referrer": "https://google.com", // Optional, the referrer URL
  "search_query": "my search query" // Optional, the search query if coming from a search engine
}

レスポンス

{
  "dashboardUrl": "https://visitor.6developer.com/dashboard?domain=example.com",
  "totalCount": 42,
  "todayCount": 5
}

fetch('https://visitor.6developer.com/visit', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    domain: 'example.com',
    timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
    page_path: window.location.pathname,
    page_title: document.title,
    referrer: document.referrer
  })
})
.then(response => response.json())
.then(data => console.log(data));

訪問統計を取得する

GET
/visit?domain=example.com

ウェブサイトの訪問者統計を取得します。

Query Parameters

domain: "example.com" // Required

レスポンス

{
  "dashboardUrl": "https://visitor.6developer.com/dashboard?domain=example.com",
  "totalCount": 42,
  "todayCount": 5
}

fetch('https://visitor.6developer.com/visit?domain=example.com')
  .then(response => response.json())
  .then(data => console.log(data));

統合

訪問者カウンターをウェブサイトに統合するには、次のスクリプトをHTMLに追加してください:

<script>
(function() {
  const domain = encodeURIComponent(window.location.hostname);
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
  const page_path = window.location.pathname;
  const page_title = document.title;
  const referrer = document.referrer;
  
  // Extract search query if coming from a search engine
  let search_query = '';
  if (referrer) {
    try {
      const url = new URL(referrer);
      if (url.hostname.includes('google.com')) {
        search_query = url.searchParams.get('q') || '';
      } else if (url.hostname.includes('bing.com')) {
        search_query = url.searchParams.get('q') || '';
      } else if (url.hostname.includes('yahoo.com')) {
        search_query = url.searchParams.get('p') || '';
      } else if (url.hostname.includes('duckduckgo.com')) {
        search_query = url.searchParams.get('q') || '';
      }
    } catch (e) {
      // Invalid URL, ignore
    }
  }
  
  fetch('https://visitor.6developer.com/visit', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ 
      domain, 
      timezone,
      page_path,
      page_title,
      referrer,
      search_query
    })
  })
  .then(response => response.json())
  .then(data => {
    console.log('Visitor count:', data);
    // You can display the count on your page
    if (document.getElementById('visitor-count')) {
      document.getElementById('visitor-count').textContent = data.totalCount;
    }
  })
  .catch(error => console.error('Error:', error));
})();
</script>

より詳細なインストール手順については、次を参照してください インストールガイド.

NPMパッケージ

より簡単な統合のためにNPMパッケージも提供しています:

npm install @rundevelrun/free-visitor-counter

NPMパッケージの詳細については、次を参照してください GitHubリポジトリ.

エラー処理

APIは標準のHTTPステータスコードを返します:

  • 200 OK - リクエストは成功しました。
  • 400 Bad Request - リクエストが無効でした。
  • 404 Not Found - 要求されたリソースが見つかりませんでした。
  • 500 Internal Server Error - サーバーでエラーが発生しました。

エラーレスポンス形式

{
  "error": "Error message description"
}

レート制限 - 寛大な制限

APIはIPアドレスごとに1分あたり100リクエストに制限されていますが、これはほとんどのウェブサイトにとって十分すぎるほどです。

この制限を超えると、429 Too Many Requestsレスポンスを受け取ります。

CORSポリシー

私たちのAPIは、任意のドメインからのクロスオリジンリクエストを許可しています。

始める準備はできましたか?

今日からウェブサイトの訪問者を追跡しましょう。