Skip to main content

Google Sheets Integration

Simplified Conversion Uploads with Google Sheets Integration

Updated over a week ago

At a Glance: This article will guide you on how to integrate with Google Sheets. After the integration, conversions added to the sheet will be automatically uploaded to the panel.

Overview :

Uploading conversions manually can often be repetitive and time-consuming—especially when you’re working with large numbers. To make this easier, Trackier now supports Google Sheets integration which is a smarter, more efficient way to handle bulk upload of data.

With this integration, conversion uploads become effortless and if you're managing a high volume of conversions, this integration can be a real time-saver. There's no need to manually import data into the Trackier platform. Once you add your conversion data to the Google Sheet, it will be automatically synced with your panel.

This integration eliminates the time-consuming process of bulk uploads, offering a smarter, hassle-free solution for your conversion tracking.This streamlined process not only saves time but also reduces the risk of errors associated with manual data handling. Whether you're managing hundreds or thousands of conversions, the integration simplifies the process and improves efficiency.

Key Benefits:

  • ✅ Save time with automated uploads

  • ✅ Eliminate manual errors

  • ✅ Keep data synced

  • ✅ Easily collaborate across teams

Video to Watch :

Steps to Integrate Google Sheets with Trackier

Follow the Steps Below to Ensure Your Google Sheets Data is Automatically Uploaded to the Panel:

Step 1: Access Google Apps Script

Open your Google Sheet, then navigate to Extensions > Apps Script.

You will be redirected to the following page :

Step 2: Enter the Script Code and Enter Your API Key

  • Copy Paste the CODE in the Apps Script page.

Code

function readCSVAndSendToAPI() {
try {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheets = spreadsheet.getSheets();
const apiKey = "Enter API Key";
const baseUrl = `https://api.trackier.com/v2/conversions/bulkUpload?apiKey=${encodeURIComponent(apiKey)}`;

const allowedHeaders = [
"click_id", "campaign_id", "publisher_id", "created", "payout", "revenue",
"sale_amount", "currency", "click_ip", "country", "status", "conn",
"goal_id", "goal_value", "user_id", "txn_id", "conversion_id", "note",
"sub1", "sub2", "sub3", "sub4", "sub5", "sub6", "sub7", "sub8", "sub9",
"sub10", "app_id", "app_name", "cr_name", "source", "click_time", "p1","p2","p3","p4","p5","p6","p7","p8","p9","p10", "coupon_code", "gaid", "idfa"
];

sheets.forEach(sheet => processSheet(sheet, baseUrl, allowedHeaders));
} catch (e) {
Logger.log("Error: " + e.message);
SpreadsheetApp.getUi().alert("Error: " + e.message);
}
}

function processSheet(sheet, baseUrl, allowedHeaders) {
const range = sheet.getDataRange();
const values = range.getValues();

if (values.length <= 1) {
Logger.log(`No data found in the sheet: ${sheet.getName()}`);
return;
}

const headers = values[0].map(header => header.toString().toLowerCase());
const dataList = createDataList(headers, values, allowedHeaders);

if (dataList.length === 0) {
Logger.log(`No valid data to process in sheet: ${sheet.getName()}`);
return;
}

const finalJSON = {
data: dataList,
firePostback: "yes",
fetchIpDetails: true
};

Logger.log(`Payload for sheet "${sheet.getName()}": ${JSON.stringify(finalJSON, null, 2)}`); // Log the payload before sending
sendToAPI(finalJSON, baseUrl, sheet.getName());
}

function createDataList(headers, values, allowedHeaders) {
const dataList = [];
for (let i = 1; i < values.length; i++) {
const row = values[i];
const dataObject = {};

headers.forEach((header, index) => {
const cellValue = row[index];
if (cellValue !== null && cellValue !== "") {
if (header === "geo") {
dataObject["country"] = cellValue;
} else if (header === "created_date") {
if (cellValue instanceof Date) {
const utcDate = new Date(cellValue.getTime() - (cellValue.getTimezoneOffset() * 60000));
dataObject["created"] = utcDate.toISOString(); // Convert to ISO UTC format
} else {
dataObject["created"] = cellValue; // Keep existing value if not a Date object
}
} else if (header === "goal_value") {
dataObject["goal_value"] = cellValue.toString();
} else if (allowedHeaders.includes(header)) {
dataObject[header] = cellValue;
}
}
});

if (Object.keys(dataObject).length > 0) {
dataList.push(dataObject);
}
}
return dataList;
}

function sendToAPI(finalJSON, baseUrl, sheetName) {
try {
const options = {
method: "post",
contentType: "application/json",
payload: JSON.stringify(finalJSON),
muteHttpExceptions: true
};

const response = UrlFetchApp.fetch(baseUrl, options);
const responseCode = response.getResponseCode();
const responseBody = response.getContentText();

Logger.log(`API Response for sheet "${sheetName}" - Code: ${responseCode}`);
Logger.log(`API Response for sheet "${sheetName}" - Body: ${responseBody}`);

const responseJson = JSON.parse(responseBody);

if (responseCode === 200) {
const message = responseJson.message || `Data from sheet "${sheetName}" sent successfully!`;
SpreadsheetApp.getUi().alert(message);
} else {
const errorMessage = responseJson.errors[0].message || `An error occurred while sending data from sheet "${sheetName}".`;
SpreadsheetApp.getUi().alert(`Error in sheet "${sheetName}": ${errorMessage}`);
}
} catch (e) {
Logger.log(`Error sending data for sheet "${sheetName}": ${e.message}`);
SpreadsheetApp.getUi().alert(`Error sending data for sheet "${sheetName}": ${e.message}`);
}
}
  • Copy API Key from your Trackier panel and paste it inside the double quotes ("Enter API Key") in the script code.

Step 3: Save and Run the Script

  • Click on "Save Project to Drive".

  • Then click on "Run" to execute the selected function.

Step 4: Authorize Permissions

  • A pop-up will appear requesting permission to run the script.

  • Click "Review Permissions".

  • Select your Google account and check "Select All" to proceed.

Note: Only two required permissions are needed for this to work. We do not request access to any unnecessary data.

  • Click "Continue" after granting the required permissions.

Execution and Sync Confirmation

Once authorized, a message will pop up in your Google Sheet saying:
"Job has been scheduled" — click "OK" to proceed.

After this, the data you entered in the Google Sheet will begin syncing automatically with your Trackier panel.

Once executed, the data entered in the Google Sheet will be automatically synced and visible in your Trackier panel.


We're thrilled to have put together a top-notch team of qualified experts who are available to handle any of your concerns and respond to any inquiries you may have. You can contact us at any time by sending an email to support@trackier.com or using the in-platform chat feature.

Did this answer your question?