使用GPT編寫RSA的谷歌廣告指令碼

一個使用GPT編寫RSA的谷歌廣告指令碼

這個基於GPT的谷歌RSA廣告指令碼可以幫助你利用GPT的API來使用最大數量的RSA資產,進而提升谷歌付費搜尋廣告展現機會。

有效管理PPC活動需要使用正確的工具組合。

長期以來,谷歌廣告指令碼一直是我的最愛之一,因為它們可以完全定製,具有合理的規模,並且在任何谷歌廣告賬戶中都是免費的。

但現在有一個新的孩子-GPT。我們能否將生成性人工智慧與谷歌廣告指令碼結合起來?

這是我要回答的問題,結果是我第一個使用GPT的谷歌廣告指令碼。

它確定了響應式搜尋廣告(RSA)的機會,並使用GPT來幫助生成額外的創意資產,以利用這個機會。

你可以在本文末尾抓取指令碼程式碼,並在你自己的賬戶上試用。

為什麼你應該使用RSA的最大資產數量

響應式搜尋廣告(RSA)是谷歌廣告的一種廣告格式,允許廣告商為一個廣告建立多個標題和描述。

然後,谷歌使用機器學習來測試不同的標題和描述組合,以確定哪些組合對不同的搜尋查詢和使用者環境表現最佳。

這有助於提高廣告的相關性和效能,使廣告商能夠接觸到更多的受眾。

我們發現,RSA所帶來的展現是擴充套件文字廣告的4倍,而具有更多標題變體的廣告比具有較少變體的廣告獲得更多展現。

更多標題變體的廣告比具有較少變體的廣告獲得更多展現

谷歌允許廣告商為每個RSA提交15個版本的標題和四個版本的描述。

雖然這並不意味著你的資產的43,000種變化會收集到相同的展現,但向機器提供最大數量的資產總是一個好主意,這樣它的演算法就可以向每個感興趣的使用者展示你的廣告。

但是,讓我們面對現實吧,為你賬戶中的每一個廣告組寫15個偉大的標題和4個長的描述可能會變得很乏味。因此,許多廣告商在他們的RSA中存在差距,這並不奇怪。

PPC管理工具可以很容易地發現和解決這個問題。但也有一些方法可以在不支付額外軟體的情況下大規模地做到這一點。

谷歌廣告指令碼是對廣告賬戶進行批量操作的最佳免費工具之一。

去年,作者和長期從事PPC的思想領袖、Twitter上#ppcchat的創始人Matt Umbro一起寫了一個指令碼,建立了一個資產丟失的RSA廣告列表。

但那是在ChatGPT提高公眾對生成性人工智慧的認識之前。因此,我決定看看我是否能結合指令碼和GPT的API來改善廣告賬戶。

使用指令碼

該指令碼建立了一個電子表格,每一行和每一列都有一個RSA,用於每個標題和描述資產。

RSA電子表格

當RSA沒有使用谷歌允許的最大數量的變化時,它會呼叫GPT API來建議額外的廣告文字變化。

這些人工智慧生成的建議然後被放置在電子表格中,以便被批量載入到谷歌,從而輕鬆地建立缺少的資產。

為了便於檢視GPT生成的內容,這些單元格被自動填充為綠色。

GPT生成的谷歌廣告內容

為了執行這個指令碼,你需要從OpenAI的網站上獲得一個API金鑰,並將金鑰新增到指令碼第39行左右的位置:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var OPEN_AI_API_KEY = ''; // get your own API key at https://platform.openai.com/account/api-keys
var OPEN_AI_API_KEY = ''; // get your own API key at https://platform.openai.com/account/api-keys
var OPEN_AI_API_KEY = ''; // get your own API key at https://platform.openai.com/account/api-keys

你可以在預覽模式下執行該指令碼,並檢視日誌以獲得新電子表格的URL。

檢視日誌以獲得新電子表格的URL

每次指令碼執行時,它都會使用OpenAI的API。這要花錢,所以不要把這個指令碼放在自動任務計劃上。

下載指令碼

在這裡獲取一份程式碼副本

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/******************************************
* RSA Report
* @version: 3.0
* @authors: Naman Jindal (Optmyzr), Frederick Vallaeys (Optmyzr)
* -------------------------------
* Install this script in your Google Ads account (not an MCC account)
* to generate a Google Sheet with a list of all your responsive search ads
* and their headlines and descriptions.
* For RSAs that are not using the maximum number of allowed variations,
* this script will suggest new variations for headlines and descriptions
* using the OpenAI GPT API.
* The resulting sheet can be bulk uploaded back into Google Ads.
* --------------------------------
* For more PPC tools, visit www.optmyzr.com.
******************************************/
// If Blank script will create a new Google sheet everytime it runs.
var SS_URL = '';
// Name of the tab in the Google sheet.
var TAB_NAME = 'RSA';
// Flag to decide if the script checks only ads in active campaigns and active ad groups
var INCLUDE_PAUSED = false;
// only include ads with this many or fewer headlines on the output spreadsheet (defaults to 15)
var MAX_HEADLINES = 15;
// only include ads with this many or fewer descriptions on the output spreadsheet (defaults to 4)
var MAX_DESCRIPTIONS = 4;
// Multiple emails can be added sepearated by comma (,)
// Used for access to spreadsheet and for sending email
var EMAIL = '';
// Set to true if you want to recieve the report on Email.
var SEND_EMAIL = false;
var OPEN_AI_API_KEY = ''; // get your own API key at https://platform.openai.com/account/api-keys
var GPT_MODEL = 'gpt-3.5-turbo';
// Do not edit anything below this line
function main() {
var output = [[
'Account ID', 'Account Name', 'Campaign', 'Ad Group', 'Ad ID', '# Headlines', '# Descriptions', 'Ad Strength',
'Headline 1', 'Headline 2', 'Headline 3', 'Headline 4', 'Headline 5', 'Headline 6', 'Headline 7', 'Headline 8', 'Headline 9',
'Headline 10', 'Headline 11', 'Headline 12', 'Headline 13', 'Headline 14', 'Headline 15',
'Description Line 1', 'Description Line 2', 'Description Line 3', 'Description Line 4'
]];
var columCount = output[0].length;
var backgroupHeader = [];
while(backgroupHeader.length < columCount) {
backgroupHeader.push('#ffffff');
}
var backgrounds = [backgroupHeader];
var accId = AdsApp.currentAccount().getCustomerId(),
accName = AdsApp.currentAccount().getName();
var query = [
'SELECT campaign.name, ad_group.name, ad_group_ad.ad.id, ad_group_ad.ad_strength,',
'ad_group_ad.ad.responsive_search_ad.headlines, ad_group_ad.ad.responsive_search_ad.descriptions',
'FROM ad_group_ad WHERE ad_group_ad.ad.type = RESPONSIVE_SEARCH_AD AND metrics.impressions >= 0',
INCLUDE_PAUSED ? '' : 'AND ad_group_ad.status = ENABLED AND campaign.status = ENABLED and ad_group.status = ENABLED',
'AND segments.date DURING LAST_7_DAYS'
].join(' ');
var rows = AdsApp.report(query).rows();
while(rows.hasNext()) {
var row = rows.next();
var headlines = row['ad_group_ad.ad.responsive_search_ad.headlines'];
var headlineCount = headlines.length;
var descriptions = row['ad_group_ad.ad.responsive_search_ad.descriptions'];
var descriptionCount = descriptions.length;
if(headlineCount > MAX_HEADLINES || descriptionCount > MAX_DESCRIPTIONS) { continue; }
var out = [
accId, accName, row['campaign.name'], row['ad_group.name'], row['ad_group_ad.ad.id'],
headlineCount, descriptionCount, row['ad_group_ad.ad_strength']
];
var bgRow = ['#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff'];
var headlinesText = [];
for(var z in headlines) {
headlinesText.push(headlines[z].text);
bgRow.push('#ffffff');
}
var diff = 15 - headlinesText.length;
var autoHeadlines = [];
if(diff > 0) {
autoHeadlines = generateTextOpenAI('Find '+diff+' more ad headlines under 30 characters that are similar to these:\n', headlinesText);
}
if(autoHeadlines.length) {
headlinesText = headlinesText.concat(autoHeadlines);
for(var i = 0; i < autoHeadlines.length; i++) {
bgRow.push('#d9ead3');
}
}
while(headlinesText.length < 15) {
headlinesText.push('');
bgRow.push('#fffff')
}
while(headlinesText.length > 15) {
headlinesText.pop();
bgRow.pop();
}
var descriptionsText = [];
for(var z in descriptions) {
descriptionsText.push(descriptions[z].text);
bgRow.push('#ffffff');
}
var diff = 4 - descriptions.length;
var autoDescriptions = [];
if(diff > 0) {
autoDescriptions = generateTextOpenAI('Find '+diff+' more ad descriptions under 90 characters that are similar to these:\n', descriptionsText);
}
if(autoDescriptions.length) {
descriptionsText = descriptionsText.concat(autoDescriptions);
for(var i = 0; i < autoDescriptions.length; i++) {
bgRow.push('#d9ead3');
}
}
while(descriptionsText.length < 4) {
descriptionsText.push('');
bgRow.push('#ffffff');
}
while(descriptionsText.length > 4) {
descriptionsText.pop();
bgRow.pop();
}
out = out.concat(headlinesText).concat(descriptionsText);
backgrounds.push(bgRow);
output.push(out);
}
if(!SS_URL) {
var ss = SpreadsheetApp.create(accName + ': RSA Report');
SS_URL = ss.getUrl();
if(EMAIL) {
ss.addEditors(EMAIL.split(','));
}
}
Logger.log('Report URL: ' + SS_URL);
var ss = SpreadsheetApp.openByUrl(SS_URL);
var tab = ss.getSheetByName(TAB_NAME);
if(!tab) {
tab = ss.getSheetByName('Sheet1');
if(!tab) {
tab = ss.insertSheet(TAB_NAME);
} else {
tab.setName(TAB_NAME)
}
}
tab.clearContents();
tab.setFrozenRows(1);
tab.getRange(1,1,output.length,output[0].length).setValues(output).setBackgrounds(backgrounds).setFontFamily('Calibri');
if(EMAIL && SEND_EMAIL) {
MailApp.sendEmail(EMAIL, accName + ' RSA Report is ready', 'Report is available at below link:\n'+SS_URL);
}
}
function getGoogleAdsFormattedDate(d, format){
var date = new Date();
date.setDate(date.getDate() - d);
return Utilities.formatDate(date,AdsApp.currentAccount().getTimeZone(),format);
}
function generateTextOpenAI(question, texts) {
//texts.pop();
var prompt = question + texts.join('\n');
var messages= [
{"role": "user", "content": prompt}
];
var payload = {
"model": GPT_MODEL,
"messages": messages
};
var httpOptions = {
"method" : "POST",
"muteHttpExceptions": true,
"contentType": "application/json",
"headers" : {
"Authorization" : 'Bearer ' + OPEN_AI_API_KEY
},
'payload': JSON.stringify(payload)
};
//Logger.log(JSON.stringify(payload));
var response = JSON.parse(UrlFetchApp.fetch('https://api.openai.com/v1/chat/completions', httpOptions));
var choices = response['choices'];
var texts = [];
if(choices && choices[0] && choices[0]['message']) {
var output = choices[0]['message']['content'].split('\n');
for(var z in output) {
if(!output[z].trim()) { continue; }
var parts = output[z].split('. ');
if(parts.length > 1) {
parts.shift();
}
texts.push(parts.join('. '));
}
} else {
//Logger.log('No results found!')
Logger.log(response);
}
return texts;
}
/****************************************** * RSA Report * @version: 3.0 * @authors: Naman Jindal (Optmyzr), Frederick Vallaeys (Optmyzr) * ------------------------------- * Install this script in your Google Ads account (not an MCC account) * to generate a Google Sheet with a list of all your responsive search ads * and their headlines and descriptions. * For RSAs that are not using the maximum number of allowed variations, * this script will suggest new variations for headlines and descriptions * using the OpenAI GPT API. * The resulting sheet can be bulk uploaded back into Google Ads. * -------------------------------- * For more PPC tools, visit www.optmyzr.com. ******************************************/ // If Blank script will create a new Google sheet everytime it runs. var SS_URL = ''; // Name of the tab in the Google sheet. var TAB_NAME = 'RSA'; // Flag to decide if the script checks only ads in active campaigns and active ad groups var INCLUDE_PAUSED = false; // only include ads with this many or fewer headlines on the output spreadsheet (defaults to 15) var MAX_HEADLINES = 15; // only include ads with this many or fewer descriptions on the output spreadsheet (defaults to 4) var MAX_DESCRIPTIONS = 4; // Multiple emails can be added sepearated by comma (,) // Used for access to spreadsheet and for sending email var EMAIL = ''; // Set to true if you want to recieve the report on Email. var SEND_EMAIL = false; var OPEN_AI_API_KEY = ''; // get your own API key at https://platform.openai.com/account/api-keys var GPT_MODEL = 'gpt-3.5-turbo'; // Do not edit anything below this line function main() { var output = [[ 'Account ID', 'Account Name', 'Campaign', 'Ad Group', 'Ad ID', '# Headlines', '# Descriptions', 'Ad Strength', 'Headline 1', 'Headline 2', 'Headline 3', 'Headline 4', 'Headline 5', 'Headline 6', 'Headline 7', 'Headline 8', 'Headline 9', 'Headline 10', 'Headline 11', 'Headline 12', 'Headline 13', 'Headline 14', 'Headline 15', 'Description Line 1', 'Description Line 2', 'Description Line 3', 'Description Line 4' ]]; var columCount = output[0].length; var backgroupHeader = []; while(backgroupHeader.length < columCount) { backgroupHeader.push('#ffffff'); } var backgrounds = [backgroupHeader]; var accId = AdsApp.currentAccount().getCustomerId(), accName = AdsApp.currentAccount().getName(); var query = [ 'SELECT campaign.name, ad_group.name, ad_group_ad.ad.id, ad_group_ad.ad_strength,', 'ad_group_ad.ad.responsive_search_ad.headlines, ad_group_ad.ad.responsive_search_ad.descriptions', 'FROM ad_group_ad WHERE ad_group_ad.ad.type = RESPONSIVE_SEARCH_AD AND metrics.impressions >= 0', INCLUDE_PAUSED ? '' : 'AND ad_group_ad.status = ENABLED AND campaign.status = ENABLED and ad_group.status = ENABLED', 'AND segments.date DURING LAST_7_DAYS' ].join(' '); var rows = AdsApp.report(query).rows(); while(rows.hasNext()) { var row = rows.next(); var headlines = row['ad_group_ad.ad.responsive_search_ad.headlines']; var headlineCount = headlines.length; var descriptions = row['ad_group_ad.ad.responsive_search_ad.descriptions']; var descriptionCount = descriptions.length; if(headlineCount > MAX_HEADLINES || descriptionCount > MAX_DESCRIPTIONS) { continue; } var out = [ accId, accName, row['campaign.name'], row['ad_group.name'], row['ad_group_ad.ad.id'], headlineCount, descriptionCount, row['ad_group_ad.ad_strength'] ]; var bgRow = ['#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff']; var headlinesText = []; for(var z in headlines) { headlinesText.push(headlines[z].text); bgRow.push('#ffffff'); } var diff = 15 - headlinesText.length; var autoHeadlines = []; if(diff > 0) { autoHeadlines = generateTextOpenAI('Find '+diff+' more ad headlines under 30 characters that are similar to these:\n', headlinesText); } if(autoHeadlines.length) { headlinesText = headlinesText.concat(autoHeadlines); for(var i = 0; i < autoHeadlines.length; i++) { bgRow.push('#d9ead3'); } } while(headlinesText.length < 15) { headlinesText.push(''); bgRow.push('#fffff') } while(headlinesText.length > 15) { headlinesText.pop(); bgRow.pop(); } var descriptionsText = []; for(var z in descriptions) { descriptionsText.push(descriptions[z].text); bgRow.push('#ffffff'); } var diff = 4 - descriptions.length; var autoDescriptions = []; if(diff > 0) { autoDescriptions = generateTextOpenAI('Find '+diff+' more ad descriptions under 90 characters that are similar to these:\n', descriptionsText); } if(autoDescriptions.length) { descriptionsText = descriptionsText.concat(autoDescriptions); for(var i = 0; i < autoDescriptions.length; i++) { bgRow.push('#d9ead3'); } } while(descriptionsText.length < 4) { descriptionsText.push(''); bgRow.push('#ffffff'); } while(descriptionsText.length > 4) { descriptionsText.pop(); bgRow.pop(); } out = out.concat(headlinesText).concat(descriptionsText); backgrounds.push(bgRow); output.push(out); } if(!SS_URL) { var ss = SpreadsheetApp.create(accName + ': RSA Report'); SS_URL = ss.getUrl(); if(EMAIL) { ss.addEditors(EMAIL.split(',')); } } Logger.log('Report URL: ' + SS_URL); var ss = SpreadsheetApp.openByUrl(SS_URL); var tab = ss.getSheetByName(TAB_NAME); if(!tab) { tab = ss.getSheetByName('Sheet1'); if(!tab) { tab = ss.insertSheet(TAB_NAME); } else { tab.setName(TAB_NAME) } } tab.clearContents(); tab.setFrozenRows(1); tab.getRange(1,1,output.length,output[0].length).setValues(output).setBackgrounds(backgrounds).setFontFamily('Calibri'); if(EMAIL && SEND_EMAIL) { MailApp.sendEmail(EMAIL, accName + ' RSA Report is ready', 'Report is available at below link:\n'+SS_URL); } } function getGoogleAdsFormattedDate(d, format){ var date = new Date(); date.setDate(date.getDate() - d); return Utilities.formatDate(date,AdsApp.currentAccount().getTimeZone(),format); } function generateTextOpenAI(question, texts) { //texts.pop(); var prompt = question + texts.join('\n'); var messages= [ {"role": "user", "content": prompt} ]; var payload = { "model": GPT_MODEL, "messages": messages }; var httpOptions = { "method" : "POST", "muteHttpExceptions": true, "contentType": "application/json", "headers" : { "Authorization" : 'Bearer ' + OPEN_AI_API_KEY }, 'payload': JSON.stringify(payload) }; //Logger.log(JSON.stringify(payload)); var response = JSON.parse(UrlFetchApp.fetch('https://api.openai.com/v1/chat/completions', httpOptions)); var choices = response['choices']; var texts = []; if(choices && choices[0] && choices[0]['message']) { var output = choices[0]['message']['content'].split('\n'); for(var z in output) { if(!output[z].trim()) { continue; } var parts = output[z].split('. '); if(parts.length > 1) { parts.shift(); } texts.push(parts.join('. ')); } } else { //Logger.log('No results found!') Logger.log(response); } return texts; }
/******************************************
* RSA Report
* @version: 3.0
* @authors: Naman Jindal (Optmyzr), Frederick Vallaeys (Optmyzr)
* -------------------------------
* Install this script in your Google Ads account (not an MCC account)
* to generate a Google Sheet with a list of all your responsive search ads
* and their headlines and descriptions.
* For RSAs that are not using the maximum number of allowed variations,
* this script will suggest new variations for headlines and descriptions 
* using the OpenAI GPT API.
* The resulting sheet can be bulk uploaded back into Google Ads.
* --------------------------------
* For more PPC tools, visit www.optmyzr.com.
******************************************/

// If Blank script will create a new Google sheet everytime it runs.
var SS_URL = ''; 

// Name of the tab in the Google sheet.
var TAB_NAME = 'RSA';

// Flag to decide if the script checks only ads in active campaigns and active ad groups
var INCLUDE_PAUSED = false;

// only include ads with this many or fewer headlines on the output spreadsheet (defaults to 15)
var MAX_HEADLINES = 15;

// only include ads with this many or fewer descriptions on the output spreadsheet (defaults to 4)
var MAX_DESCRIPTIONS = 4;

// Multiple emails can be added sepearated by comma (,)
// Used for access to spreadsheet and for sending email
var EMAIL = '';

// Set to true if you want to recieve the report on Email.
var SEND_EMAIL = false;

var OPEN_AI_API_KEY = ''; // get your own API key at https://platform.openai.com/account/api-keys

var GPT_MODEL = 'gpt-3.5-turbo';

// Do not edit anything below this line
function main() {
  
  var output = [[
    'Account ID', 'Account Name', 'Campaign', 'Ad Group', 'Ad ID', '# Headlines', '# Descriptions', 'Ad Strength', 
    'Headline 1', 'Headline 2', 'Headline 3', 'Headline 4', 'Headline 5', 'Headline 6', 'Headline 7', 'Headline 8', 'Headline 9', 
    'Headline 10', 'Headline 11', 'Headline 12', 'Headline 13', 'Headline 14', 'Headline 15', 
    'Description Line 1', 'Description Line 2', 'Description Line 3', 'Description Line 4'
  ]];
  
  var columCount = output[0].length;
  var backgroupHeader = [];
  while(backgroupHeader.length < columCount) {
    backgroupHeader.push('#ffffff');
  }
  
  var backgrounds = [backgroupHeader];
  
  var accId = AdsApp.currentAccount().getCustomerId(),
      accName = AdsApp.currentAccount().getName();
  
  var query = [
    'SELECT campaign.name, ad_group.name, ad_group_ad.ad.id, ad_group_ad.ad_strength,',
    'ad_group_ad.ad.responsive_search_ad.headlines, ad_group_ad.ad.responsive_search_ad.descriptions',
    'FROM ad_group_ad WHERE ad_group_ad.ad.type = RESPONSIVE_SEARCH_AD AND metrics.impressions >= 0',
    INCLUDE_PAUSED ? '' : 'AND ad_group_ad.status = ENABLED AND campaign.status = ENABLED and ad_group.status = ENABLED',
    'AND segments.date DURING LAST_7_DAYS'
  ].join(' ');
  
  var rows = AdsApp.report(query).rows();
  while(rows.hasNext()) {
    var row = rows.next();
    
    var headlines = row['ad_group_ad.ad.responsive_search_ad.headlines'];
    var headlineCount = headlines.length;
    
    var descriptions = row['ad_group_ad.ad.responsive_search_ad.descriptions'];
    var descriptionCount = descriptions.length;
    
    if(headlineCount > MAX_HEADLINES || descriptionCount > MAX_DESCRIPTIONS) { continue; }
    
    var out = [
      accId, accName, row['campaign.name'], row['ad_group.name'], row['ad_group_ad.ad.id'],
      headlineCount, descriptionCount, row['ad_group_ad.ad_strength']
    ];
    
    var bgRow = ['#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff'];
    
    var headlinesText = [];
    for(var z in headlines) {
      headlinesText.push(headlines[z].text);
      bgRow.push('#ffffff');
    }
    
    var diff = 15 - headlinesText.length;
    
    var autoHeadlines = [];
    if(diff > 0) {
      autoHeadlines = generateTextOpenAI('Find '+diff+' more ad headlines under 30 characters that are similar to these:\n', headlinesText);
    }
    
    if(autoHeadlines.length) {
      headlinesText = headlinesText.concat(autoHeadlines);
      for(var i = 0; i < autoHeadlines.length; i++) {
        bgRow.push('#d9ead3');
      }
    }
    
    while(headlinesText.length < 15) {
      headlinesText.push('');
      bgRow.push('#fffff')
    }
    
    while(headlinesText.length > 15) {
      headlinesText.pop();
      bgRow.pop();
    }
    
    var descriptionsText = [];
    for(var z in descriptions) {
      descriptionsText.push(descriptions[z].text);
      bgRow.push('#ffffff');
    }
    
    var diff = 4 - descriptions.length;
    var autoDescriptions = [];
    if(diff > 0) {
      autoDescriptions = generateTextOpenAI('Find '+diff+' more ad descriptions under 90 characters that are similar to these:\n', descriptionsText);
    }
    
    if(autoDescriptions.length) {
      descriptionsText = descriptionsText.concat(autoDescriptions);
      for(var i = 0; i < autoDescriptions.length; i++) {
        bgRow.push('#d9ead3');
      }
    }
    
    while(descriptionsText.length < 4) {
      descriptionsText.push('');
      bgRow.push('#ffffff');
    }
    
    while(descriptionsText.length > 4) {
      descriptionsText.pop();
      bgRow.pop();
    }
    
    out = out.concat(headlinesText).concat(descriptionsText);
    
    backgrounds.push(bgRow);
    output.push(out);
  }
  
  if(!SS_URL) {
    var ss = SpreadsheetApp.create(accName + ': RSA Report');
    SS_URL = ss.getUrl(); 
    
    if(EMAIL) { 
      ss.addEditors(EMAIL.split(','));
    }
  }
  
  Logger.log('Report URL: ' + SS_URL);
  var ss = SpreadsheetApp.openByUrl(SS_URL);
  var tab = ss.getSheetByName(TAB_NAME);
  if(!tab) {
    tab = ss.getSheetByName('Sheet1');
    if(!tab) {
     tab = ss.insertSheet(TAB_NAME);
    } else {
     tab.setName(TAB_NAME) 
    }
  }
  
  tab.clearContents();
  tab.setFrozenRows(1);
  tab.getRange(1,1,output.length,output[0].length).setValues(output).setBackgrounds(backgrounds).setFontFamily('Calibri');
  
  if(EMAIL && SEND_EMAIL) {
    MailApp.sendEmail(EMAIL, accName + ' RSA Report is ready', 'Report is available at below link:\n'+SS_URL);
  }
}

function getGoogleAdsFormattedDate(d, format){
  var date = new Date();
  date.setDate(date.getDate() - d);
  return Utilities.formatDate(date,AdsApp.currentAccount().getTimeZone(),format);
}

function generateTextOpenAI(question, texts) {
  
  //texts.pop();
  var prompt = question + texts.join('\n');
  
  var messages= [
    {"role": "user", "content": prompt}
  ];
  
  var payload = {
    "model": GPT_MODEL,
    "messages": messages
  };
  
  var httpOptions = {
    "method" : "POST",
    "muteHttpExceptions": true,
    "contentType": "application/json",
    "headers" : {
      "Authorization" : 'Bearer ' + OPEN_AI_API_KEY  
    },
    'payload': JSON.stringify(payload)
  };
  
  //Logger.log(JSON.stringify(payload));
  var response = JSON.parse(UrlFetchApp.fetch('https://api.openai.com/v1/chat/completions', httpOptions));
  var choices = response['choices'];
  
  var texts = [];
  if(choices && choices[0] && choices[0]['message']) {
    var output = choices[0]['message']['content'].split('\n');
    for(var z in output) {
      if(!output[z].trim()) { continue; }
      var parts = output[z].split('. ');
      if(parts.length > 1) {
        parts.shift();
      }
      texts.push(parts.join('. '));
    }
  } else {
    //Logger.log('No results found!')
    Logger.log(response);
  }
  
  return texts;
}

如果你是谷歌廣告指令碼的新手,你可以按照這裡的說明進行首次設定。

GPT生成谷歌廣告語和關鍵詞的侷限性

雖然GPT在寫作方面很出色,但它在計數方面卻出了名的糟糕。我問它為什麼,它是這樣解釋的:

“作為一個人工智慧語言模型,GPT(Generative Pre-trained Transformer)在數學方面本質上並不差。然而,它的表現可能不如專門的數學模型,因為它沒有經過專門的數學任務訓練。GPT主要是為自然語言處理而設計的,這涉及理解和生成人類語言。雖然它可以進行基本的數學運算,但它可能會在更復雜的計算中掙扎”。

對於我們的PPC用例,你必須仔細檢查它建議的資產長度,以確保它們符合谷歌的字元限制。

當我要求GPT在每個建議的標題旁邊新增字元數時,你可以看到它通常很接近,但會出錯:

GPT生成標題字元數

經驗告訴我,GPT在完成一項任務時傾向於遵循提示中發現的模式。

這意味著在處理現有的標題列表時,它更有可能寫出適當長度的標題,就像你目前在你的賬戶中的那些標題一樣。

因此,該指令碼在完成只缺少幾個元素的RSA時效果最好,而不是大部分或全部元素。

正如你在前面的截圖中所看到的,它有時也傾向於給出編號的建議列表,而當你的每個標題都以’1)’、’2)’等開頭時,這並不是一個好的廣告。

我不會讓GPT自動生成廣告,因為我對讓谷歌的一些建議進行自動化感到猶豫。

當我不小心開啟了自動應用冗餘關鍵詞的建議時,它把我的品牌關鍵詞Optmyzr從我的賬戶中移除。

把GPT的工作作為一個建議,幫助加快生成新的廣告變體。

將谷歌廣告與生成性人工智慧相結合

GPT是網際網路發明以來最令人興奮的新技術之一。

它對問題的理解程度和它的反應的自信(儘管並不總是準確的)是令人震驚的。

我很高興在我的PPC工具包中擁有另一個神奇的工具,以幫助我的廣告勝過競爭對手。

我希望這個指令碼能讓你體會到,當你把谷歌廣告和GPT這樣的生成性人工智慧結合起來時,會有什麼可能。

評論留言