https://www.google-analytics.com/collect?v=1&t=event&tid=UA-160685285-1&cid=50454954-60b8-4d14-9d36-a96297abd634&ec=GATrackDemo&ea=Menu%20click%2019&el=updateThisSheet&ev=1&uid=4ffbf3a699177b1ed9e0c1e6dffc01b635e20e589b12a4ed7ab93ab164006b00
Now what does not work.
In order to setup the analytics in Apps Script I have followed tips and ideas from Martin Hawksey and Romain Vialard.
When I use the add-on and try to send a hit to GA it never gets registered. I get no erros and I am able to get the 200 response code from google analytics server.
Here is the minimal code:
Code.js
[UPDATE] As noted by Martin, there was no cid in the code below, I have tested it before with the cid as well with not luck, added it below for reference
function onOpen(e) { var menu = SpreadsheetApp.getUi().createMenu('Menu'); menu.addItem('Hit GA', 'hitGaTest').addToUi();}
function onInstall(e){ onOpen();
function hitGaTest(){ var payload = 'v=1&t=event&tid=UA-160685285-1&cid=50454954-60b8-4d14-9d36-a96297abd634&ec=GATrackDemo&ea=Menu%20click%2019&el=updateThisSheet&ev=1&uid=4ffbf3a699177b1ed9e0c1e6dffc01b635e20e589b12a4ed7ab93ab164006b00'; var options = {'method' : 'POST', 'payload' : payload}; var rep_code = UrlFetchApp.fetch('https://www.google-analytics.com/collect', options).getResponseCode();
// Same issue with this `batch` // var rep_code = UrlFetchApp.fetch('https://www.google-analytics.com/batch', options).getResponseCode(); console.log(rep_code); // 200}
appscript.json
"timeZone": "Europe/Lisbon", "dependencies": { "enabledAdvancedServices": [{ "userSymbol": "Calendar", "serviceId": "calendar", "version": "v3" }] }, "exceptionLogging": "STACKDRIVER", "oauthScopes": ["https://www.googleapis.com/auth/spreadsheets", "runtimeVersion": "V8", "executionApi": {"access": "ANYONE"}}
Is anyone here using GA in their add-ons that could check that it is still working?
Things I have tried and didn't work:
- Different browsers for running the script
- Publishing the add-on in G Suite Marketplace (as unlisted)
- Running the add-on from another developer account (different person in another country)
- Sending the request to either https://www.google-analytics.com/collect or https://www.google-analytics.com/batch end points
- Using Martin's GATrack code
Please help debugging this
Kind regards,
Victor
PS Wish you all a coding life free of bugs :)
To help with debugging you can also hit a validation URL https://www.google-analytics.com/debug/collect?tid=fake&v=1
More details in https://developers.google.com/analytics/devguides/collection/protocol/v1/validating-hits
Hope that helps
Martin
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0d55b541-4d2a-4984-a919-55f8a5094ff4%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/rtdzKUOEDZ0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/7908f3d3-5b90-4ca4-9506-aa2552feb47c%40googlegroups.com.