-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgeoip-target-filter.html
41 lines (39 loc) · 1.62 KB
/
geoip-target-filter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<script>
/*!
* GeoIP Target Filter
* Project: https://github.com/OpenAff/geoip-target-filter
*
* ---------------------------------------------------------------------
* A small snippet for geo-filter redirection using GeoIP API.
* Add your targeted country's "ISO 3166-1 - Alpha-2" codes to the filter
* to automatically redirect targeted visitors to your targeted URL and
* to non-targeted URL otherwise.
*
* Country Codes can be found @( Wikipedia - http://bit.ly/nWBMYz )
* See Column: "Alpha-2 Code"
* ---------------------------------------------------------------------
*/
var filter = ['US', 'GB', 'CA', 'AU', 'IN'];
var targetVisitorsUrl = 'https://domain.tld/';
var allVisitorsUrl = 'https://nontarget.domain.tld/';
// ------------------------------------------------------
// DON'T EDIT THE BELOW CODE UNLESS REQUIRED
// ------------------------------------------------------
/**
* Check if the visitor is from targeted country, Redirect to target URL.
* Otherwise to non-target URL.
*/
function geoip(g){window.top.location.href=inArray(g.country,filter)?targetVisitorsUrl:allVisitorsUrl}
function inArray(r,n){for(var t=n.length,e=0;t>e;e++)if(n[e]==r)return!0;return!1}
</script>
<script src="https://get.geojs.io/v1/ip/country.js?callback=geoip"></script>
</head>
<body>
<p>Please wait...</p>
</body>
</html>