Streamline your data collection by connecting the LinksToro extension directly to Google Sheets. This integration automatically saves domain analysis data to a spreadsheet, creating a centralized database for your projects. Follow this simple guide to set it up.

Setting Up the Google Sheets Connector

The setup process involves creating a simple script in your Google account that will act as a bridge between the extension and your spreadsheet.

Create and Deploy the Google Apps Script

  1. Create a new spreadsheet.
  2. Navigate to Google Apps Script and start a New Project.
Google Apps Script
  1. Give the project a recognizable name, such as “LinksToro Connector.”
  2. Delete the default code in the editor and paste in the provided script code for the integration. Replace ___ in the code with your SPREADSHEET_ID, which can be found in the spreadsheet URL.
Google Apps Script code
Click to see the code

/**
* Handles POST requests from the LinksToro extension to add data to a Google Sheet.
*/
function doPost(e) {
try {
let data;
let values;

// The spreadsheet ID where data will be stored.
// IMPORTANT: You can replace this with your own spreadsheet ID if you use the “Advanced Configuration” steps.
const SPREADSHEET_ID = ‘___’; // Placeholder ID from original script

// Attempt to parse incoming data (handles both JSON and form data)
if (e.postData && e.postData.contents) {
if (e.postData.type === ‘application/json’) {
data = JSON.parse(e.postData.contents);
values = data.values;
} else {
const formData = e.parameter;
if (formData.data) {
data = JSON.parse(formData.data);
values = data.values;
} else {
throw new Error(‘No data provided in postData’);
}
}
} else {
throw new Error(‘No valid postData received’);
}

if (!values || !Array.isArray(values) || values.length === 0) {
throw new Error(‘Parsed data does not contain valid values array.’);
}

const spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
const sheet = spreadsheet.getActiveSheet();

// If the sheet is empty, set up the header row
if (sheet.getLastRow() === 0) {
const headers = [
‘Timestamp’, ‘Page URL’, ‘Domain IP’, ‘Domain Rating’,
‘Referring Domains’, ‘Linked Domains’, ‘Organic Traffic’,
‘Organic Keywords’, ‘Top Country’, ‘Emails’, ‘Contact Page’, ‘Social Links’
];
sheet.getRange(1, 1, 1, headers.length).setValues([headers]).setFontWeight(‘bold’);
}

// Append the new data rows
sheet.getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length).setValues(values);

// Auto-resize columns for better readability
sheet.autoResizeColumns(1, values[0].length);

// Return a success response
return ContentService.createTextOutput(JSON.stringify({
success: true,
message: ‘Data added successfully’,
spreadsheetUrl: spreadsheet.getUrl()
})).setMimeType(ContentService.MimeType.JSON);

} catch (error) {
// Log any errors for debugging
console.error(‘Error in doPost:’, error.toString());

// Return an error response
return ContentService.createTextOutput(JSON.stringify({
success: false,
error: error.toString()
})).setMimeType(ContentService.MimeType.JSON);
}
}

/**
* Handles GET requests to the script URL to confirm it’s running.
*/
function doGet(e) {
return ContentService.createTextOutput(JSON.stringify({
success: true,
message: ‘LinksToro Google Apps Script is running correctly. Ready to receive POST requests.’
})).setMimeType(ContentService.MimeType.JSON);
}

/**
* A utility function to create the spreadsheet and set headers manually if needed.
* To run this, select ‘setupSpreadsheet’ from the function dropdown in the Apps Script editor and click ‘Run’.
*/
function setupSpreadsheet() {
const SPREADSHEET_ID = ‘___’; // Make sure this is the correct ID
const spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
const sheet = spreadsheet.getActiveSheet();

if (sheet.getLastRow() === 0) {
const headers = [
‘Timestamp’, ‘Page URL’, ‘Domain IP’, ‘Domain Rating’,
‘Referring Domains’, ‘Linked Domains’, ‘Organic Traffic’,
‘Organic Keywords’, ‘Top Country’, ‘Emails’, ‘Contact Page’, ‘Social Links’
];
sheet.getRange(1, 1, 1, headers.length).setValues([headers]).setFontWeight(‘bold’);
SpreadsheetApp.flush();
console.log(‘Spreadsheet headers have been set up successfully.’);
} else {
console.log(‘Spreadsheet already has content. Headers were not changed.’);
}
}

  1. Click the Deploy button and select New deployment.
New deployment
  1. In the configuration window, set the following options:
    • Type: Select Web app.
    • Execute as: Me.
    • Who has access: Anyone.
Web app details
  1. Click Deploy. You will be asked to authorize the script’s permissions; please approve them.
  2. After deployment, Google will provide a Web app URL. Copy this URLโ€”you’ll need it for the final step.
Web app URL

โœ… Correct URL: https://script.google.com/macros/s/SCRIPT_ID/exec
โŒ Incorrect URL: https://docs.google.com/spreadsheets/d/SHEET_ID/edit

Connect the Extension to Your Script

  1. Open the LinksToro extension in your browser and go to the Domain Info tab.
  2. Find the “Google Sheets URL” field and paste the Web app URL you copied in the previous step.
  3. Click Test Connection to Worksheet to check if it works.
  4. The extension will save the URL. The connection is now active! Click the button Add Domain to Worksheet to import domain info to your spreadsheet.
LinkToro integration

Data Collected

Once connected, the extension will send the following data points to your spreadsheet each time you add a domain:

ColumnDescription
TimestampThe date and time the data was added
Page URLThe URL of the page that was analyzed
Domain IPThe IP address of the domain
Domain RatingThe Ahrefs Domain Rating score
Referring DomainsTotal number of domains linking to the site
Linked DomainsTotal number of domains the site links to
Organic TrafficEstimated monthly organic search traffic
Organic KeywordsEstimated number of keywords the site ranks for
Top CountryThe country that provides the most traffic
EmailsAny email addresses found on the site
Contact PageThe URL of the site’s contact page
Social LinksLinks to the site’s social media profiles

Final words

By completing this setup, you’ve transformed your data collection process. This powerful integration streamlines your workflow, ensuring valuable domain insights are captured automatically in a single, accessible location. You’re now equipped for a more efficient and organized approach to your projects.


Leave a Reply

Your email address will not be published. Required fields are marked *