用于检查IP是否在欧盟的URL

时间:2019-04-18 15:32:02

标签: json ip amp-html

有人知道是否可以检查IP地址是否在欧盟吗?我正在尝试在我的网站上实施Cookie通知,但是仅在法律要求时才显示。

我正在尝试使用AMP来实现这一点,它提供了使用URL检查是否应显示通知的选项。我知道这可能是一个遥远的尝试,但是它需要返回如下结果:(基于请求所来自的URL)。

{
   "showNotification":true
}

我可能最终会创建一些东西,只是想检查某个人已经做过的偶然机会

1 个答案:

答案 0 :(得分:0)

我刚刚想出了如何使用amp-geo来完成此操作-我想我可以分享答案,以防其他人遇到它:

包括以下JS文件:

<script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>
<script async custom-element="amp-geo" src="https://cdn.ampproject.org/v0/amp-geo-0.1.js"></script>

包括此代码:

<amp-geo layout="nodisplay">
  <script type="application/json">
  {
    "ISOCountryGroups": {
      "ineu": ["al","ad","at","az","by","be","ba","bg","hr","cy","cz","dk","ee","fi","fr","ge","de","gr","hu","is","ie", "it","kz","xk","lv","li","lt","lu","mk","mt","md","mc","me","nl","no","pl","pt","ro","ru","sm","rs","sk", "si","es","se","ch","tr","ua","gb","va"]
    }
  }
  </script>
</amp-geo>

<amp-user-notification id="cookie-notif" layout="nodisplay" data-show-if-geo="ineu">
    <div>
        This site uses third-party cookies, <a href="/privacy/">learn more</a> or <a on="tap:cookie-notif.dismiss" class="ampstart-btn caps ml1">accept</a>
    </div>
</amp-user-notification>