{"id":24078127,"url":"https://github.com/melogabriel/lead-to-gsheet-appscript","last_synced_at":"2026-06-18T09:31:36.033Z","repository":{"id":255204956,"uuid":"848858619","full_name":"melogabriel/lead-to-gsheet-appscript","owner":"melogabriel","description":"This Google Apps Script allows you to log form submission data directly to a Google Sheet using Google Tag Manager. The script listens for GET or POST requests, processes the data, and writes it to the specified Google Sheet.","archived":false,"fork":false,"pushed_at":"2025-10-26T23:18:31.000Z","size":19,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T01:14:53.195Z","etag":null,"topics":["appscript","github-pages","google-sheets","google-tag-manager","javascript"],"latest_commit_sha":null,"homepage":"https://melogabriel.github.io/lead-to-gsheet-appscript/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/melogabriel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"buy_me_a_coffee":"gabrielmelo"}},"created_at":"2024-08-28T14:33:23.000Z","updated_at":"2025-10-26T23:18:34.000Z","dependencies_parsed_at":"2025-02-26T23:40:58.384Z","dependency_job_id":"5e272aed-204b-428a-aee5-863278c888ad","html_url":"https://github.com/melogabriel/lead-to-gsheet-appscript","commit_stats":null,"previous_names":["melogabriel/lead-to-gsheet-appscript"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/melogabriel/lead-to-gsheet-appscript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melogabriel%2Flead-to-gsheet-appscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melogabriel%2Flead-to-gsheet-appscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melogabriel%2Flead-to-gsheet-appscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melogabriel%2Flead-to-gsheet-appscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/melogabriel","download_url":"https://codeload.github.com/melogabriel/lead-to-gsheet-appscript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melogabriel%2Flead-to-gsheet-appscript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34485163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appscript","github-pages","google-sheets","google-tag-manager","javascript"],"created_at":"2025-01-09T21:01:19.578Z","updated_at":"2026-06-18T09:31:36.005Z","avatar_url":"https://github.com/melogabriel.png","language":"JavaScript","funding_links":["https://buymeacoffee.com/gabrielmelo"],"categories":[],"sub_categories":[],"readme":"[![Deploy GitHub Pages](https://github.com/melogabriel/lead-to-gsheet-appscript/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/melogabriel/lead-to-gsheet-appscript/actions/workflows/jekyll-gh-pages.yml)\n\n# Google Sheets Data Logger for Google Tag Manager\n\nThis Google Apps Script allows you to log form submission data directly to a Google Sheet using Google Tag Manager. The script listens for `GET` or `POST` requests, processes the data, and writes it to the specified Google Sheet.\n\n## Features\n\n- **Easy Integration**: Seamlessly integrates with Google Tag Manager to log data to Google Sheets.\n- **Timestamp Logging**: Automatically adds a timestamp to each logged entry.\n- **Error Handling**: Includes basic error handling to ensure reliable data logging.\n\n## Setup Instructions\n\n### Step 1: Set Up Your Google Sheet\n\n1. **Create a New Google Sheet**: Go to [Google Sheets](https://sheets.google.com) and create a new spreadsheet.\n2. **Name Your Sheet**: Name your sheet, and ensure you have a sheet named `Sheet1` or update the script to match the name of your sheet.\n3. **Set Up Headers**: In the first row of your sheet, add headers for the data you want to log. For example:\n   - [`Timestamp`](get-timestamp.js)\n   - `Name`\n   - `Email`\n   - `Message`\n   - Any other data you need to log\n\n### Step 2: Add the Script to Google Apps Script\n\n1. **Open Script Editor**: In your Google Sheet, click on `Extensions \u003e Apps Script` to open the script editor.\n2. **Copy the Script**: Copy the following script into the script editor:\n\n    ```javascript\n    // Usage\n    // 1. Enter sheet name where data is to be written below\n    var SHEET_NAME = 'Sheet1';\n    var SHEET_KEY = 'your-sheet-key';\n\n    var SCRIPT_PROP = PropertiesService.getScriptProperties();\n\n    function doGet(e){\n      return handleResponse(e);\n    }\n\n    function doPost(e){\n      return handleResponse(e);\n    }\n\n    function handleResponse(e) {\n      var lock = LockService.getPublicLock();\n      lock.waitLock(30000);\n\n      try {\n        var doc = SpreadsheetApp.openById(SHEET_KEY);\n        var sheet = doc.getSheetByName(SHEET_NAME);\n        var headRow = e.parameter.header_row || 1;\n        var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];\n        var nextRow = sheet.getLastRow()+1;\n        var row = [];\n        for (var i = 0; i \u003c headers.length; i++) {\n          if (headers[i] === 'Timestamp') {\n            row.push(new Date());\n          } else {\n            // Use header name to get data from the parameters\n            row.push(e.parameter[headers[i]] || ''); // Default to empty string if parameter is missing\n          }\n        }\n        sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);\n\n        return ContentService\n          .createTextOutput(JSON.stringify({'result':'success', 'row': nextRow}))\n          .setMimeType(ContentService.MimeType.JSON);\n      } catch(e){\n        return ContentService\n          .createTextOutput(JSON.stringify({'result':'error', 'error': e}))\n          .setMimeType(ContentService.MimeType.JSON);\n      } finally {\n        lock.releaseLock();\n      }\n    }\n    ```\n\n3. **Replace `SHEET_KEY`**: Replace the `SHEET_KEY` variable with your Google Sheet’s ID. You can find the ID in the URL of your Google Sheet. It’s the long string of characters between `/d/` and `/edit`.\n\n4. **Save and Deploy**: Save your script and click on `Deploy \u003e Test deployments` to run it initially. Then click on `Deploy \u003e Manage deployments` and deploy the script as a web app. Make sure you set the permissions to \"Anyone, even anonymous\".\n\n### Step 3: Set Up Google Tag Manager\n\nTo send data from Google Tag Manager to your Google Sheets via the script you just set up, follow these steps:\n\n1. **Create a New Tag**:\n    - In Google Tag Manager, click on `Tags \u003e New` and choose `Tag Configuration \u003e Custom Image`.\n    - In the **Image URL** field, paste your Google Apps Script Web App URL.\n\n    - Append the parameters you want to pass from Google Tag Manager to your Google Sheet in the URL, like this:\n\n    ```\n    https://script.google.com/macros/s/YOUR_SCRIPT_URL/exec?Name={{Form Name Variable}}\u0026Email={{Form Email Variable}}\u0026Message={{Form Message Variable}}\n    ```\n\n    - Replace `YOUR_SCRIPT_URL` with the URL of your deployed Google Apps Script.\n    - Replace `{{Form Name Variable}}`, `{{Form Email Variable}}`, and `{{Form Message Variable}}` with the appropriate variables capturing the form data in Google Tag Manager.\n\n2. **Create a Trigger**:\n    - Under \"Triggering,\" click on `Trigger Configuration` and select a trigger that captures the form submission or the event where you want to log data.\n    - For example, you can create a `Form Submission` trigger if you're capturing data from a form, or use an existing trigger that fires when the desired event occurs.\n\n3. **Test Your Tag**:\n    - Use Google Tag Manager’s `Preview` mode to test your tag and ensure that data is being sent to your Google Sheets correctly.\n    - Check your Google Sheet to see if the data appears as expected.\n\n4. **Publish Your Tag**:\n    - Once everything is working correctly, click `Submit` in Google Tag Manager to publish your changes.\n\n### Example Usage\n\nIf your Google Sheet has the headers `Timestamp`, `Name`, `Email`, and `Message`, and your script is deployed, the data sent through your Google Tag Manager tag will be logged to your Google Sheet with a timestamp.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nIf you have any suggestions or improvements, feel free to submit an issue or a pull request.\n\n## Acknowledgments\n\n- **Google Sheets**: For providing an easy-to-use platform for managing data.\n- **Google Tag Manager**: For making it easy to manage tags across websites.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelogabriel%2Flead-to-gsheet-appscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelogabriel%2Flead-to-gsheet-appscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelogabriel%2Flead-to-gsheet-appscript/lists"}