Private Geolocation API - Documentação Completa
URL Base: https://sua-api.com
Abra seu Google Tag Manager → Tags → Nova → HTML Personalizado
Copie e cole o código completo no campo HTML da tag:
<script>
(function() {
// === CONFIGURAÇÃO ===
var API_URL = 'https://SUA-API.COM/locate';
var API_KEY = 'kds-api-key-2026'; // opcional
// Monta headers
var headers = {};
if (API_KEY) {
headers['x-api-key'] = API_KEY;
}
// Faz a requisição
fetch(API_URL, { headers: headers })
.then(function(response) { return response.json(); })
.then(function(data) {
// Envia para o dataLayer
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'geo_location',
'geo_ip': data.ipAddress,
'geo_country': data.countryCode,
'geo_country_name': data.countryName,
'geo_region': data.region,
'geo_city': data.city,
'geo_coordinates': data.cityLatLong,
'geo_browser': data.browser,
'geo_os': data.os,
'geo_device': data.device
});
console.log('KDS GeoAPI:', data);
})
.catch(function(err) {
console.error('KDS GeoAPI Error:', err);
});
})();
</script>
Gatilho: All Pages (Page View) ou DOM Ready
Salve e publique as alterações no GTM
Após configurar a tag, crie estas variáveis no GTM:
| Variável | Tipo | Data Layer Variable Name |
|---|---|---|
| GEO - IP | Data Layer | geo_ip |
| GEO - País | Data Layer | geo_country |
| GEO - País Nome | Data Layer | geo_country_name |
| GEO - Estado | Data Layer | geo_region |
| GEO - Cidade | Data Layer | geo_city |
| GEO - Dispositivo | Data Layer | geo_device |
Condition: geo_country equals BR
Condition: geo_device equals mobile
curl -H "x-api-key: kds-api-key-2026" https://SUA-API.COM/locate
curl -H "Origin: https://seudominio.com" https://SUA-API.COM/locate
fetch('https://SUA-API.COM/locate', {
headers: {'x-api-key': 'kds-api-key-2026'}
})
.then(r => r.json())
.then(data => console.log(data));
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://SUA-API.COM/locate'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['x-api-key: kds-api-key-2026']); $response = curl_exec($ch); $data = json_decode($response, true);
import requests
headers = {'x-api-key': 'kds-api-key-2026'}
response = requests.get('https://SUA-API.COM/locate', headers=headers)
data = response.json()
const fetch = require('node-fetch');
const response = await fetch('https://SUA-API.COM/locate', {
headers: {'x-api-key': 'kds-api-key-2026'}
});
const data = await response.json();
const ALLOWED_DOMAINS = [ 'localhost', '127.0.0.1', 'seudominio.com', 'www.seudominio.com' ]; // Para liberar todos os domínios: const ALLOW_ALL_DOMAINS = true;
const API_KEY = 'sua-chave-secreta-aqui';
const PORT = process.env.PORT || 3000;
| Header | Descrição |
|---|---|
x-forwarded-for |
IP do cliente (proxy) |
cf-connecting-ip |
IP do Cloudflare |
x-real-ip |
IP real do Nginx |
{
"authorized": true,
"ipAddress": "177.142.50.100",
"countryCode": "BR",
"countryName": "Brazil",
"region": "SP",
"city": "São Paulo",
"cityLatLong": "-23.5505,-46.6333",
"browser": "Chrome",
"browserVersion": "120.0.0.0",
"os": "Windows",
"osVersion": "11",
"device": "desktop"
}
PORT=3000 NODE_ENV=production