How do I automate the generation of a CSV file when a new row is added to a Google Sheet?

76 views
Skip to first unread message

Dan Konig

unread,
Jun 24, 2020, 9:50:03 AM6/24/20
to Google Apps Script Community
I am trying to figure out a way to automate the creation of a CSV file that will be automatically uploaded to Google Analytics but I am trying to figure out how best to do that. I believe that is going to involve Apps Script to some degree.

  1.  User submits a form
  2. Google Sheet is updated with form info
  3. Google sheet creates a csv file and saves it somewhere when a new row is added.
  4. That CSV file is automatically uploaded to Google Analytics once it is created.
Any ideas where to start with this?

Darren D'Mello

unread,
Jun 27, 2020, 7:46:27 AM6/27/20
to google-apps-sc...@googlegroups.com
Did you mean the CSV file must be saved in Google drive?

You can use the on submit trigger of spreadsheet and whenever a response is received.

Let us know.

--
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/be9e039b-7893-426e-a3a7-bc9b5921693bo%40googlegroups.com.

dank...@creativetown.com

unread,
Jun 27, 2020, 9:02:33 AM6/27/20
to Google Apps Script Community
Sure. That would work especially if it makes it easier to upload to Google Analytics.

Darren D'Mello

unread,
Jun 27, 2020, 9:39:45 AM6/27/20
to google-apps-sc...@googlegroups.com
Are you looking for paid assistance. I am ready to take up.

Please drop me an email through this form www.digitalthoughts.science/contact

There is also a consultant directory whom you are free to avail the services from others as well.

Adam Morris

unread,
Jun 27, 2020, 10:11:10 AM6/27/20
to Google Apps Script Community
Hi there,

It's an interesting workflow.

First thing to establish is if there is an endpoint for Google Analytics to accept an upload of a CSV file. It may well have it. More likely, however, it'll offer an API where you can update data, which may be what you need instead.

You can use appscripts to do something that responds to when there is a new row added, for sure. But to automate it you'll have to identify the endpoint on the other end, what does it need? Then it's a matter of shaping the data that you get when the user submits the form, to be in that format.

I found some example code that might get you started. It shows how to convert a range into CSV, and uploads it to google drive.
Message has been deleted

dank...@creativetown.com

unread,
Jun 29, 2020, 9:25:40 AM6/29/20
to Google Apps Script Community
Sorry for the delay. Thanks for getting back to me. 
  1. I figured an API would be involved. 
  2. The CSV file should be in the format that is needed for the upload to Google Analytics.
  3. I took a brief look at the code and ran through the responses. I'm not sure yet what issues I will run into if a brand new file with a different URL is created every time.
  4. I think this is the AP I need to take advantage of.  https://developers.google.com/analytics/devguides/config/mgmt/v3/data-import
  5. I'm really a newb programmer and everything I've stated up to this point may be completely off point and not the best way to do any of it.

Clark Lind

unread,
Jul 11, 2020, 7:53:49 AM7/11/20
to Google Apps Script Community
Since both are Google products, I figured there had to be an easier way. Analytics should be able to link directly to the sheet. I found this tutorial which may solve your issue without having to export and import a csv file:
https://www.ryanpraski.com/google-analytics-cost-data-import-google-sheets-automated/

Clark Lind

unread,
Jul 11, 2020, 7:57:22 AM7/11/20
to Google Apps Script Community
Just read the whole thing, looks like the guy wrote an apps script to do it.

dank...@creativetown.com

unread,
Jul 13, 2020, 1:54:35 PM7/13/20
to Google Apps Script Community
It's a pretty good article although a bit dated. Some of the latter steps don't appear to be needed or perhaps they need to be accomplished a different way. I'm not really keen on importing fake data into my live environment so I may need to set up a new view to test it out. What I am particularly interested in is how do I automate the upload when a new row is added. That doesn't appear to be covered. I also realized that I never considered that the rows are view dependent. I'd need to create some logic that would parse out the rows by view before the upload unless the size of the payload is really small. Then I would just upload the same list to all views and let Google sort things out.
Reply all
Reply to author
Forward
0 new messages