简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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