🗺️ KDS GeoAPI

Private Geolocation API - Documentação Completa

🎯 Testar API

URL Base: https://sua-api.com

Testar Agora

Status
Aguardando teste...

🔧 Google Tag Manager

1

Crie uma Tag no GTM

Abra seu Google Tag Manager → Tags → Nova → HTML Personalizado

2

Cole o código abaixo

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>
3

Configure o Gatilho

Gatilho: All Pages (Page View) ou DOM Ready

4

Publique a tag

Salve e publique as alterações no GTM

📊 Criar Variáveis 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

🎯 Exemplos de Uso no GTM

Trigger: Apenas visitantes do Brasil

Condition: geo_country equals BR

Trigger: Apenas dispositivos móveis

Condition: geo_device equals mobile

💻 Uso via cURL / Código

Com API Key

curl -H "x-api-key: kds-api-key-2026" https://SUA-API.COM/locate

Com Origin

curl -H "Origin: https://seudominio.com" https://SUA-API.COM/locate

JavaScript (Frontend)

fetch('https://SUA-API.COM/locate', {
  headers: {'x-api-key': 'kds-api-key-2026'}
})
.then(r => r.json())
.then(data => console.log(data));

PHP

$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);

Python

import requests

headers = {'x-api-key': 'kds-api-key-2026'}
response = requests.get('https://SUA-API.COM/locate', headers=headers)
data = response.json()

Node.js

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();

⚙️ Configuração do Servidor

Arquivo: server.js

Domínios Permitidos

const ALLOWED_DOMAINS = [
  'localhost',
  '127.0.0.1',
  'seudominio.com',
  'www.seudominio.com'
];

// Para liberar todos os domínios:
const ALLOW_ALL_DOMAINS = true;

API Key

const API_KEY = 'sua-chave-secreta-aqui';

Alterar Porta

const PORT = process.env.PORT || 3000;

Headers suportados

Header Descrição
x-forwarded-for IP do cliente (proxy)
cf-connecting-ip IP do Cloudflare
x-real-ip IP real do Nginx

Response Completo

{
  "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"
}

Variáveis de Ambiente (Docker/EasyPanel)

PORT=3000
NODE_ENV=production