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

# Link Analytics

> Get analytics on shortened links

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "basic") {
      displayPlans = ["Basic", "Premium", "Business", "Enterprise"];
    } else if (lowerCasePlan === "business") {
      displayPlans = ["Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["business"]} maxPackRequired={true} />

Return analytics for all shortened links or a single link for a given link ID. For example:

<ul class="custom-bullets">
  <li>`https://api.ayrshare.com/api/links/yC0fTl` returns analytics for ID `yC0fTl`</li>
  <li>`https://api.ayrshare.com/api/links` returns all link analytics.</li>
</ul>

## Header Parameters

<HeaderAPI noProfileKey />

## Path Parameters

<ParamField path="id" type="string">
  Provide the shortened link ID returned from the POST /links request as a path parameter. For
  example: `https://api.ayrshare.com/api/links/yC0fTl` If no link ID is provided, all links are
  returned.
</ParamField>

## Query Parameters

<ParamField query="fromCreatedDate" type="string">
  Get history of links shortened after this date. Accepts a UTC date time.

  For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
  Please see [utctime](https://www.utctime.net/) for more examples.
</ParamField>

<ParamField query="toCreatedDate" type="string">
  Get history of links shortened before this date. Accepts a UTC date time.

  For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
  Please see [utctime](https://www.utctime.net/) for more examples.
</ParamField>

<ParamField query="fromClickDate" type="string">
  Get history of links clicked after this date. Accepts a UTC date time.

  For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
  Please see [utctime](https://www.utctime.net/) for more examples.
</ParamField>

<ParamField query="toClickDate" type="string">
  Get history of links clicked before this date. Accepts a UTC date time.

  For example, use format `YYYY-MM-DDThh:mm:ssZ` and send as `2026-07-08T12:30:00Z`.
  Please see [utctime](https://www.utctime.net/) for more examples.
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_Key" \
  -H 'Content-Type: application/json' \
  -X GET https://api.ayrshare.com/api/links/yC0fTl
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch(`https://api.ayrshare.com/api/links/yC0fTl`, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`
        }
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer API_KEY'}

  r = requests.delete('https://api.ayrshare.com/api/links/yC0fTl',
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php
  require 'vendor/autoload.php';    // Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html

  $lastdays = "2";
  $client = new GuzzleHttp\Client();
  $res = $client->request(
      'GET',
      'https://api.ayrshare.com/api/links/yC0fTl',
      [
          'headers' => [
              'Content-Type'      => 'application/json',
              'Authorization'     => 'Bearer API_KEY'
          ]
      ]
  );

  echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
  ```

  ```csharp C# theme={"system"}
  using System;

  using System.Net.Http;
  using System.Threading.Tasks;

  namespace LinksGETRequest_csharp
  {
  class Links
  {
  private static readonly HttpClient client = new HttpClient();

      static async Task Main(string[] args)
      {
          string API_KEY = "API_KEY";
          string url = "https://api.ayrshare.com/api/links/yC0fTl";

          client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

          try
          {
              var response = await client.GetStringAsync(url);
              Console.WriteLine(response);
          }
          catch (HttpRequestException e)
          {
              Console.WriteLine($"Error: {e.Message}");
          }
      }
  }

  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Analytics on a Link theme={"system"}
  {
      "status": "success",
      "analytics": {
          "browserCounts": {
              "chrome": 15
          },
          "created": "2023-06-29T00:57:12.220Z",
          "id": "yC0fTl",
          "originalUrl": "https://www.ayrshare.com/?utm_source=google_ads",
          "refererCounts": {},
          "shortUrl": "https://ayrs.io/yC0fTl",
          "socialClicks": {},
          "status": "success",
          "totalClicks": 15,
          "utmSource": "google_ads"
      }
  }
  ```

  ```json 200: Analytics on all Links theme={"system"}
  {
    "status": "success",
    "analytics": [
      {
        "browserCounts": {
          "chrome": 3
        },
        "created": "2023-04-07T22:33:41.126Z",
        "id": "pHXlbv9JlRxrXj6rstdMu",
        "originalUrl": "https://www.ayrshare.com/",
        "refererCounts": {},
        "shortUrl": "https://ayrs.io/pHXlbv9JlRxrXj6rstdMu",
        "socialClicks": {},
        "totalClicks": 3
      },
      {
        "browserCounts": {
          "edge": 13
        },
        "created": "2023-07-17T15:20:51.118Z",
        "id": "yC0fTl",
        "originalUrl": "https://www.ayrshare.com/?utm_source=looking",
        "refererCounts": {},
        "shortUrl": "https://ayrs.io/yC0fTl",
        "socialClicks": {},
        "totalClicks": 13,
        "utmSource": "looking"
      }
    ]
  }
  ```

  ```json 400: Bad Request theme={"system"}
  {
    "status": "error",
    "message": "Unable to find link ID: yC0fTl",
    "code": 187
  }
  ```
</ResponseExample>
