Call Google Ads Script From Drive Script
Call Google Ads Script From Drive Script
Zac Cannon
July 3, 2024
Are you running a Google Ads script in an account and don't want to give away the secret sauce? Fortunately there is a simple solution to this which involves your Google Drive account. Here's how to set it up.
A simple solution is to upload a variation of your main Google Ads script into your Google Drive account. You can then take advantage of a simple external method called getFilesByName in the Class DriveApp in order to find and evaluate this script from the Google Ads interface, and then call any functions within said script. For simplicity here the two scripts will be called either the caller script (the script to run in Google Ads), or the main script (the script executing on your Google Ads account)
Here's what you need to do
Take your main script and amend so that the script is wrapped inside externalScript and each function to be run is inside its own this keyword. Ensure to find and replace as below
This takes advantage of the this keyword
function externalScript(activeSheet) {
this.main = function() {
// place your first function code here
Logger.log('Main function executing.');
}
//for any second function that needs to run, simply wrap the second function within your main script with another this keyword i.e
this.secondFunction = function() {
// place second function code here, if necessary
}
}
Then you will need to run the below script within Google Ads in order to call your Google Drive script.
Replace the script name in the settings with the name of the file stored in Google Drive
This script will take your script name, find the file in Google Drive, and then run its functions
If you need to push any data to a spreadsheet, ensure to define the spreadsheet within the caller script below and push this as an argument when evaluating the script. Donβt house any spreadsheet variables in the main script, due to how permissions work in Google Drive
You'll notice the externalScript variable, as your code was wrapped around this in your main script
function main() {
// settings
var scriptName = "";
// If you are pushing values to a spreadsheet, then define it here
var scriptText = getScript(scriptName);
var spreadsheet = SpreadsheetApp.openByUrl('');
var activeSheet = spreadsheet.getSheetByName('');
if (scriptText) {
Logger.log("Running script: "+scriptName);
eval(scriptText);
var script = eval('new '+externalScript+'(activeSheet);');
//function caller for the external script
script.main();
// second function caller for the external script if needed
script.secondFunction();
}
}
// find your script within Google Drive
function getScript(scriptName) {
var fileIterator = DriveApp.getFilesByName(scriptName);
if (fileIterator.hasNext()) {
var fileCheck = fileIterator.next();
if (fileIterator.hasNext()) {
Logger.log("Duplicate file found with name "+scriptName+".");
}
return fileCheck.getBlob().getDataAsString();
}
else {
Logger.log(scriptName+" not found.");
return;
}
}
Then upload your main Ads Script to your Google Drive, and run the call Google Drive Script. As simple as that, no prying eyes on your script!
Call Google Ads Script From Drive Script
Call Google Ads Script From Drive Script
Zac Cannon
July 3, 2024
Are you running a Google Ads script in an account and don't want to give away the secret sauce? Fortunately there is a simple solution to this which involves your Google Drive account. Here's how to set it up.
A simple solution is to upload a variation of your main Google Ads script into your Google Drive account. You can then take advantage of a simple external method called getFilesByName in the Class DriveApp in order to find and evaluate this script from the Google Ads interface, and then call any functions within said script. For simplicity here the two scripts will be called either the caller script (the script to run in Google Ads), or the main script (the script executing on your Google Ads account)
Here's what you need to do
Take your main script and amend so that the script is wrapped inside externalScript and each function to be run is inside its own this keyword. Ensure to find and replace as below
This takes advantage of the this keyword
function externalScript(activeSheet) {
this.main = function() {
// place your first function code here
Logger.log('Main function executing.');
}
//for any second function that needs to run, simply wrap the second function within your main script with another this keyword i.e
this.secondFunction = function() {
// place second function code here, if necessary
}
}
Then you will need to run the below script within Google Ads in order to call your Google Drive script.
Replace the script name in the settings with the name of the file stored in Google Drive
This script will take your script name, find the file in Google Drive, and then run its functions
If you need to push any data to a spreadsheet, ensure to define the spreadsheet within the caller script below and push this as an argument when evaluating the script. Donβt house any spreadsheet variables in the main script, due to how permissions work in Google Drive
You'll notice the externalScript variable, as your code was wrapped around this in your main script
function main() {
// settings
var scriptName = "";
// If you are pushing values to a spreadsheet, then define it here
var scriptText = getScript(scriptName);
var spreadsheet = SpreadsheetApp.openByUrl('');
var activeSheet = spreadsheet.getSheetByName('');
if (scriptText) {
Logger.log("Running script: "+scriptName);
eval(scriptText);
var script = eval('new '+externalScript+'(activeSheet);');
//function caller for the external script
script.main();
// second function caller for the external script if needed
script.secondFunction();
}
}
// find your script within Google Drive
function getScript(scriptName) {
var fileIterator = DriveApp.getFilesByName(scriptName);
if (fileIterator.hasNext()) {
var fileCheck = fileIterator.next();
if (fileIterator.hasNext()) {
Logger.log("Duplicate file found with name "+scriptName+".");
}
return fileCheck.getBlob().getDataAsString();
}
else {
Logger.log(scriptName+" not found.");
return;
}
}
Then upload your main Ads Script to your Google Drive, and run the call Google Drive Script. As simple as that, no prying eyes on your script!
Call Google Ads Script From Drive Script
Call Google Ads Script From Drive Script
Zac Cannon
July 3, 2024
Are you running a Google Ads script in an account and don't want to give away the secret sauce? Fortunately there is a simple solution to this which involves your Google Drive account. Here's how to set it up.
A simple solution is to upload a variation of your main Google Ads script into your Google Drive account. You can then take advantage of a simple external method called getFilesByName in the Class DriveApp in order to find and evaluate this script from the Google Ads interface, and then call any functions within said script. For simplicity here the two scripts will be called either the caller script (the script to run in Google Ads), or the main script (the script executing on your Google Ads account)
Here's what you need to do
Take your main script and amend so that the script is wrapped inside externalScript and each function to be run is inside its own this keyword. Ensure to find and replace as below
This takes advantage of the this keyword
function externalScript(activeSheet) {
this.main = function() {
// place your first function code here
Logger.log('Main function executing.');
}
//for any second function that needs to run, simply wrap the second function within your main script with another this keyword i.e
this.secondFunction = function() {
// place second function code here, if necessary
}
}
Then you will need to run the below script within Google Ads in order to call your Google Drive script.
Replace the script name in the settings with the name of the file stored in Google Drive
This script will take your script name, find the file in Google Drive, and then run its functions
If you need to push any data to a spreadsheet, ensure to define the spreadsheet within the caller script below and push this as an argument when evaluating the script. Donβt house any spreadsheet variables in the main script, due to how permissions work in Google Drive
You'll notice the externalScript variable, as your code was wrapped around this in your main script
function main() {
// settings
var scriptName = "";
// If you are pushing values to a spreadsheet, then define it here
var scriptText = getScript(scriptName);
var spreadsheet = SpreadsheetApp.openByUrl('');
var activeSheet = spreadsheet.getSheetByName('');
if (scriptText) {
Logger.log("Running script: "+scriptName);
eval(scriptText);
var script = eval('new '+externalScript+'(activeSheet);');
//function caller for the external script
script.main();
// second function caller for the external script if needed
script.secondFunction();
}
}
// find your script within Google Drive
function getScript(scriptName) {
var fileIterator = DriveApp.getFilesByName(scriptName);
if (fileIterator.hasNext()) {
var fileCheck = fileIterator.next();
if (fileIterator.hasNext()) {
Logger.log("Duplicate file found with name "+scriptName+".");
}
return fileCheck.getBlob().getDataAsString();
}
else {
Logger.log(scriptName+" not found.");
return;
}
}
Then upload your main Ads Script to your Google Drive, and run the call Google Drive Script. As simple as that, no prying eyes on your script!
Call Google Ads Script From Drive Script
Call Google Ads Script From Drive Script
Zac Cannon
July 3, 2024
Are you running a Google Ads script in an account and don't want to give away the secret sauce? Fortunately there is a simple solution to this which involves your Google Drive account. Here's how to set it up.
A simple solution is to upload a variation of your main Google Ads script into your Google Drive account. You can then take advantage of a simple external method called getFilesByName in the Class DriveApp in order to find and evaluate this script from the Google Ads interface, and then call any functions within said script. For simplicity here the two scripts will be called either the caller script (the script to run in Google Ads), or the main script (the script executing on your Google Ads account)
Here's what you need to do
Take your main script and amend so that the script is wrapped inside externalScript and each function to be run is inside its own this keyword. Ensure to find and replace as below
This takes advantage of the this keyword
function externalScript(activeSheet) {
this.main = function() {
// place your first function code here
Logger.log('Main function executing.');
}
//for any second function that needs to run, simply wrap the second function within your main script with another this keyword i.e
this.secondFunction = function() {
// place second function code here, if necessary
}
}
Then you will need to run the below script within Google Ads in order to call your Google Drive script.
Replace the script name in the settings with the name of the file stored in Google Drive
This script will take your script name, find the file in Google Drive, and then run its functions
If you need to push any data to a spreadsheet, ensure to define the spreadsheet within the caller script below and push this as an argument when evaluating the script. Donβt house any spreadsheet variables in the main script, due to how permissions work in Google Drive
You'll notice the externalScript variable, as your code was wrapped around this in your main script
function main() {
// settings
var scriptName = "";
// If you are pushing values to a spreadsheet, then define it here
var scriptText = getScript(scriptName);
var spreadsheet = SpreadsheetApp.openByUrl('');
var activeSheet = spreadsheet.getSheetByName('');
if (scriptText) {
Logger.log("Running script: "+scriptName);
eval(scriptText);
var script = eval('new '+externalScript+'(activeSheet);');
//function caller for the external script
script.main();
// second function caller for the external script if needed
script.secondFunction();
}
}
// find your script within Google Drive
function getScript(scriptName) {
var fileIterator = DriveApp.getFilesByName(scriptName);
if (fileIterator.hasNext()) {
var fileCheck = fileIterator.next();
if (fileIterator.hasNext()) {
Logger.log("Duplicate file found with name "+scriptName+".");
}
return fileCheck.getBlob().getDataAsString();
}
else {
Logger.log(scriptName+" not found.");
return;
}
}
Then upload your main Ads Script to your Google Drive, and run the call Google Drive Script. As simple as that, no prying eyes on your script!
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
Β© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
Β© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
Β© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
Β© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated