> For the complete documentation index, see [llms.txt](https://doc.commandersact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.commandersact.com/fr/fonctionnalites/sources/sources-catalog/web/containers/geoloc-api.md).

# API Geoloc

### Présentation

L’ **API Geoloc** vous permet d’enrichir les données de trafic de votre site Web avec des informations géographiques sur vos visiteurs — **sans avoir besoin de l’aide de votre équipe technique**.\
Ce service fournit des attributs de localisation précis, tels que :

* Code du continent
* Code du pays
* Région
* Ville
* Code postal
* Latitude et longitude

> **Remarque :** Geoloc est une fonctionnalité **facultative et payante**. Veuillez contacter votre **représentant commercial de Commanders Act** pour connaître les tarifs.

***

### Fonctionnement

Pour récupérer les données de géolocalisation, notre système envoie une requête au point de terminaison suivant :

```
https://api.commander1.com/geoloc?token=XXX&site=XXX
```

**Paramètres :**

| Paramètre | Description                                                                  |
| --------- | ---------------------------------------------------------------------------- |
| `token`   | Jeton API fourni par l’équipe d’assistance de Commanders Act                 |
| `site`    | ID du site (espace de travail Commanders Act) qui demande la géolocalisation |

L’API renvoie un objet JSON contenant les informations géographiques du visiteur.

#### Exemple de réponse

```json
{
  "continentCode": "EU",
  "countryCode": "FR",
  "region": "Île-de-France",
  "longitude": 2.3333,
  "latitude": 48.8667,
  "city": "Paris",
  "postalCode": "75001"
}
```

***

### Utiliser Geoloca dans votre bloc personnalisé JavaScript

Voici un exemple simple montrant comment appeler l’API et stocker le résultat dans `tC.internalvars` pour l’utiliser dans TMS. Vous pouvez utiliser ce code dans votre bloc JavaScript personnalisé.

#### Exemple de script

```javascript
function httpGet(url) {
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.open("GET", url, false); // synchronous request
  xmlHttp.send(null);
  return JSON.parse(xmlHttp.responseText);
}

tC.internalvars.geoloc = httpGet("https://api.commander1.com/geoloc/?site={YOUR SITE ID}&token={YOUR TOKEN}");
```

Une fois la valeur affectée, vous pouvez accéder directement à n’importe quel champ via internalvars

```javascript
tC.internalvars.geoloc.continentCode  // "EU"
tC.internalvars.geoloc.countryCode    // "FR"
tC.internalvars.geoloc.region         // "Île-de-France"
tC.internalvars.geoloc.longitude      // 2.3399
tC.internalvars.geoloc.latitude       // 48.8718
tC.internalvars.geoloc.city           // "Paris"
tC.internalvars.geoloc.postalCode     // "75009"
```

Ces variables peuvent désormais être utilisées pour créer vos propres règles personnalisées, par exemple pour afficher une bannière de confidentialité dans différents pays.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.commandersact.com/fr/fonctionnalites/sources/sources-catalog/web/containers/geoloc-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
