SmartNews: 50M+ premium readers, 25+ mins daily engagement, zero bots. AI targeting finds your buyers. Run native ads that actually convert.

Guide Tracking Events with Google sheets

Plamen

Super Contributor
Joined
Sep 23, 2020
Messages
32
Another day, another Google Sheets script that I'm sharing :D and will help you track events for free and optimize your landing pages. I did this because right now, on the same URL, I'm doing A/B testing of my landing pages, and they both weigh 50(50% chance to load each landing page). I wanted to see how many people visited a specific page, how many started/finished the game, and how many clicked the offer and which one to use. So, let's go straight to the point.
Step 1: Go to Google Sheets and create a new one with the desired name.
Step 2. Go to Extensions Apps Script and copy-paste the following code
JavaScript:
function doGet(e)  {
  const sheetName = e.parameter.sheet  || "DefaultSheet";  // Sheet name  from query param
  const name  = e.parameter.name || "Unnamed";
  const  lp = e.parameter.lp || "Unknown";
   const slug = e.parameter.slug || "N/A";         // Status from query param

   const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  let  sheet = spreadsheet.getSheetByName(sheetName);

  // Create  sheet if it doesn't exist
   if (!sheet) {
     sheet = spreadsheet.insertSheet(sheetName);
     // Optionally, add header row
     sheet.appendRow(["Date", "Slug", "Landing Page",  "Event Name"]);
  }

  //  Append data to the sheet
   sheet.appendRow([
    new Date(),
     slug,
     lp,
    name
   ]);

  return ContentService.createTextOutput(`Saved to  sheet "${sheetName}"`);
}
What
 

Attachments

  • Screenshot 2025-04-13 at 10.29.45.png
    Screenshot 2025-04-13 at 10.29.45.png
    77.9 KB · Views: 234
To view the premium content in our affiliate marketing forum (including this awesome thread), you must first register and upgrade your account. Register today and become a part of our amazing community!
Top