简体   繁体   English

Google Analytics(分析)-访问每个网站时显示位置访问提示

[英]Google Analytics - Location Access Prompt displayed on accessing each site

I am using Google Analytics script to triangulate the user location and their details when accessing a SharePoint Site. 访问SharePoint网站时,我正在使用Google Analytics(分析)脚本对用户位置及其详细信息进行三角测量。

We have added the Google Analytics script in the SharePoint site as an app. 我们已经在SharePoint网站中将Google Analytics(分析)脚本添加为应用程序。

A prompt is displayed "Let <user> use your location?" 出现提示“让<user>使用您的位置吗?” with Yes/No. 与是/否。

But in the Microsoft Edge user the prompt is displayed on each site even after the prompt is clicked yes. 但是在Microsoft Edge用户中,即使单击了提示,提示也会显示在每个站点上。

For retrieving the location we are using the below script code, 为了检索位置,我们使用以下脚本代码,

   navigator.geolocation.getCurrentPosition((position) => {    
                 let latitude = position.coords.latitude;
                 let longitude = position.coords.longitude;
            });

On using the above code the prompt appears. 使用上述代码时,出现提示。

My expectation is that to prevent the prompt when user access the site. 我的期望是防止用户访问该站点时出现提示。

And is there a way we can add the site to some “approved site list” in Windows or the Browser so it doesn't request. 并且有一种方法可以将站点添加到Windows或浏览器中的某些“批准的站点列表”中,因此它不会提出请求。

AFAIK, there is no way of disabling prompt. AFAIK,无法禁用提示。 Even if you specifically allow and remember location permission for every machine in your organization, it still can revoked easily via the menu in most major browsers. 即使您明确允许并记住组织中每台计算机的位置许可,也可以通过大多数主要浏览器中的菜单轻松撤销它。

Another way of achieving this is to check if location permission is given and then decide whether to initialize the app / block access to the app 实现此目的的另一种方法是检查是否提供了位置权限,然后决定是否初始化应用程序/阻止对应用程序的访问

function getLocation() {
  return new Promise((resolve, reject) => {
    navigator.geolocation.getCurrentPosition(resolve, reject);
  });
}

// then
(async function() {
  try {
    await getLocation();
    // got access
  } catch(e) {
    // no access
  }
})()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM