简体   繁体   English

我可以修改 Google Analytics 插件以在插件运行后运行 function 吗?

[英]Can I modify an Google Analytics add-on to run a function after the add-on runs?

I am running Google's Analytics Add-on for Google Sheets , for Chrome, to pull in analytics for several properties.我正在为 Google Sheets 和 Chrome 运行 Google 的 Analytics Add-on ,以获取多个属性的分析。 This runs once a day and works very well.这每天运行一次,效果很好。 Two data points that I pull are the approximate latitude and longitude of the visitor.我提取的两个数据点是访问者的大致纬度和经度。

Prior to using the add-on I used the older " magic script " written by Nick Mihailovski however this doesnt work any longer so we're advised to the add-on.在使用附加组件之前,我使用了由 Nick Mihailovski 编写的较旧的“ 魔法脚本”,但是这不再起作用,因此建议我们使用附加组件。

What I would like to do is extend the add-on such that after it populates the sheets I would like to add a column that shows the reverse geocode of the coordinates.我想做的是扩展插件,以便它填充工作表后,我想添加一个显示坐标反向地理编码的列。

I have this function that I used to modify Nick's script:我有这个 function 用来修改尼克的脚本:

 function reverse_geocode(lat,lng) {
  Utilities.sleep(1500);

 var response = Maps.newGeocoder().reverseGeocode(lat,lng);
 for (var i = 0; i < response.results.length; i++) {
   var result = response.results[i];
   Logger.log('%s: %s, %s', result.formatted_address, result.geometry.location.lat,
       result.geometry.location.lng);
   return result.formatted_address;
 }
}

I was able to modify Nick's code so that as each row was written to the sheet I could add the cell with the address from the lat/long.我能够修改尼克的代码,以便在将每一行写入工作表时,我可以添加带有纬度/经度地址的单元格。 Now I must do this manually.现在我必须手动执行此操作。 I'd like to get it back to working automatically.我想让它自动恢复工作。

Is it possible to do this with an add-on for which I can not see nor access the code?是否可以使用我看不到也无法访问代码的附加组件来做到这一点? I have tried to add this function to a file in my sheet called "geocode.gs" and tried to call it via a trigger but it does nothing.我试图将此 function 添加到我的工作表中名为“geocode.gs”的文件中,并尝试通过触发器调用它,但它什么也没做。 No visible error that I can see, nothing in the execution log either.我看不到任何可见的错误,执行日志中也没有任何内容。 Is there another way to automate this with a closed-source add-on?是否有另一种方法可以通过闭源插件自动执行此操作?

You can do this by creating a bound script in the Sheet you are running the report on.您可以通过在运行报告的工作表中创建绑定脚本来执行此操作。

If you've already tried and it doesn't work it may just be due to an error in your code.如果您已经尝试过但它不起作用,则可能只是由于您的代码中的错误。

I don't think there are add-ons that can do what you want specifically, also because doing it with the code in Google Apps Script (since you already have a function that does its job) is the quickest and most effective way.我不认为有插件可以做你想做的事,也因为使用 Google Apps 脚本中的代码(因为你已经有一个 function 可以完成它的工作)是最快和最有效的方法。

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

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