AdWords
2K members online now
2K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Ad param script not working

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Hello All,

 

We are trying to run real time priced ad copies on Google Search.

 

Log file shows the price is perfectly fetched and the value is matched with our page also.

 

Problem is that price is not reflecting in our ad copies.

 

Details are as follows: 

Campaign Name: AdParam Testing Campaign Dec 31

Label: Ad Param Campaign 1

Ad group name: Test Adgroup

Keywords: [zen x4], [zen x4 price], [zen x4 price in india], [buy zen x4] etc.

Destination URLs at keyword level is: http://cashkaro.com/zen-x4-dual-sim-mobile-phone-black-red/PPS5-31849655

 

Adcopy:

Destination URL is: cashkaro.com/zen-x4-dual-sim-mobile-phone-black-red/PPS5-31849655

 

Script Log Screenshots:

 2-24-2015 11-38-48 AM.png

 

2-24-2015 11-41-13 AM.png

 

Looking forward to hear some great thoughts on why the same is not happening?

1 Expert replyverified_user

Re: Ad param script not working

[ Edited ]
Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆

Hello,

new value for param is not reflecting in your ads in account or when you check your ads in google search?
Param allow you to change numerical values inside of an ad text without having to create a new ad. So, when param value at your feed changes the ad copy will not change but the value for param will change. Try to chek param value in Prewiev tool.

Re: Ad param script not working

Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆
When I check in Google Search.

Re: Ad param script not working

Top Contributor
# 4
Top Contributor

Hi Rohan, the screenshot of the script interface really doesn't tell us much.  Can you copy/paste the actual script you're using?

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Ad param script not working

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Where 2 check param value in Prewiev tool?

Re: Ad param script not working

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
When u go to through the Google Search once more then u will get the answer for the self.

Re: Ad param script not working

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
I can't copy/paste ur actual script because it has some rules & regulations that I cannot break.

Re: Ad param script not working

Follower ✭ ✭ ☆
# 8
Follower ✭ ✭ ☆
Just enter one of yours keywords that should cause ad with param, e.g.
http://prntscr.com/6a3hou

Re: Ad param script not working

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
There are some words which are so funny but they can be write in many ways like we say car it can be also spell as kar, cash as kash.

Re: Ad param script not working

Follower ✭ ☆ ☆
# 10
Follower ✭ ☆ ☆
Hello Gritton,

Below is the script we are using in our account:

/***
Name : Update Prices in Ads From Keyword Destination Url
Version : 1.0
Description:
This script iterates through keywords in the account and updates the price params in the ads by picking up prices from Destination Url page.
***/

//Label for campaigns to be picked up for script run
var CAMPAIGN_LABEL = 'Ad Param Campaign 1';
var currencySymbol = 'INR';


//Regex to fetch the price from Destination Page
var re = /<span itemprop="price"><span class="indianRs">Rs.<\/span>([0-9]+)<\/span><\/strong>/

//Script utilities (Do not modify)
var URL_FILE = 'Script Files/Urls Checked '+AdWordsApp.currentAccount().getCustomerId()+'.json';
var KW_FILE = 'Script Files/Kws Checked '+AdWordsApp.currentAccount().getCustomerId()+'.json';
var PREFIX = 'All AdParams Updated ' + CAMPAIGN_LABEL + ' ';

function main(){

if(finishedToday()) {
return;
} else {
clearCompletedLabel();
}

var HTTP_OPTIONS = { muteHttpExceptions:true, followRedirects:true };
var urlsAlreadyChecked = readJSONFile(URL_FILE);
if(!urlsAlreadyChecked) { urlsAlreadyChecked = {}; }
var kwsAlreadyChecked = readJSONFile(KW_FILE);
if(!kwsAlreadyChecked) { kwsAlreadyChecked = {};}

//debug('Found ' +Object.keys(urlsAlreadyChecked).length + ' already checked urls');
//debug('Found ' +Object.keys(kwsAlreadyChecked).length + ' already updated keywords');
var campIds = getCampaignsByLabel(CAMPAIGN_LABEL);
if(campIds.length == 0) { debug('No Campaigns Found with the label'); return; }

var kwUrls = getKeywordUrls(kwsAlreadyChecked, campIds);

var didExitEarly = false;
var isOutOfQuota = false;
var toChange = {};
var httpOptions = { muteHttpExceptions:true,followRedirects:true };

for(var key in kwUrls) {
var row = kwUrls[key];
var url = row.DestinationUrl;
url = cleanUrl(url);
if(!url) { continue; }
if(!urlsAlreadyChecked[url]) {
try {
var htmlCode = UrlFetchApp.fetch(url,httpOptions).getContentText();
} catch(e) {
Logger.log('There was an issue checking: '+url+' -> Skipping.');
if(e.message && e.message.indexOf('Service invoked too many times') >= 0) {
Logger.log('OUT OF QUOTA.');
isOutOfQuota = true;
break;
}
continue;
}

var matches = [];
if(re.test(htmlCode)) {
matches = getRegexMatches(re, htmlCode);
}

var adParam = (matches && matches[0]) ? matches[0] : -1;
if(adParam == -1) { kwsAlreadyChecked[row.rowKey] = 1; }
urlsAlreadyChecked[url] = { param: adParam }
}

if(urlsAlreadyChecked[url].param != -1) {
toChange[row.rowKey] = urlsAlreadyChecked[url].param;
}

if(shouldExitNow()) { didExitEarly = true; break; }
}

debug('Total Entities to Change: '+Object.keys(toChange).length);
debug('Did Exit Early? : '+didExitEarly);

if(!didExitEarly && Object.keys(toChange).length > 0) {
var ids = [];

for(var key in toChange) {
var parts = key.split('-');
ids.push([parts[0], parts[1]]);
}

var kws = AdWordsApp.keywords().withIds(ids).get();
while(kws.hasNext()){
var kw = kws.next();
var key = [kw.getAdGroup().getId(),kw.getId()].join('-');
var price = toChange[key]
if(!price) { continue; }
kw.setAdParam(1, currencySymbol+price); //param1 in ads will be replace by price value
kwsAlreadyChecked[key] = 1;
if(shouldExitRightNow()) { didExitEarly = true; break; }
}
}

if(didExitEarly || isOutOfQuota) {
writeJSONFile(URL_FILE,urlsAlreadyChecked);
writeJSONFile(KW_FILE,kwsAlreadyChecked);
} else {
var finishedLabelName = PREFIX+getDateString();
AdWordsApp.createLabel(finishedLabelName, 'Ad Params updated for the day', '#C0C0C0');
writeJSONFile(URL_FILE,{});
writeJSONFile(KW_FILE,{});
}
}

function getDateString() {
return Utilities.formatDate((new Date()), AdWordsApp.currentAccount().getTimeZone(), "yyyy-MM-dd");
}

function cleanUrl(url) {
//first check for valuetrack if parameters
url = getDesktopUrl(url);
url = replaceValueTrackParam('ifsearch',url);
if(url.indexOf('{') >= 0) {
//Let's remove the value track parameters
url = url.replace(/\{[^\}]*\}/g,'');
}

return url;
}

function getDesktopUrl(url) {
var index = url.indexOf('ifnotmobile');
if(index < 0) { return url; }
return url.match(/\{ifnotmobileSmiley Sad[\S\s]*)\}/)[1];
}

function replaceValueTrackParam(param,url) {
if(url.indexOf('{'+param+':') >= 0) {
var toReplace = getMatches(url,new RegExp('\{'+param+'Smiley Sad[^\}]*)\}','gi'),1);
if(toReplace) {
url = url.replace(new RegExp('\{'+param+'(:[^\}])*\}','gi'),toReplace);
}
}
return url;
}

function getMatches(string, regex, index) {
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}

function getKeywordUrls(kwsAlreadyChecked,campIds) {

var OPTIONS = { includeZeroImpressions : true };
var cols = ['CampaignId','CampaignName',
'AdGroupId','AdGroupName',
'Id','KeywordText','KeywordMatchType','Status',
'IsNegative','DestinationUrl','Impressions'];
var report = 'KEYWORDS_PERFORMANCE_REPORT';
var query = ['select',cols.join(','),'from',report,
'where CampaignStatus = ENABLED',
'and AdGroupStatus = ENABLED',
'and Status != REMOVED',
'and CampaignId IN [' +campIds.join(',') + ']',
'and IsNegative = false',
'during','LAST_7_DAYS'].join(' ');
var results = {};
var reportIter = AdWordsApp.report(query, OPTIONS).rows();

while(reportIter.hasNext()) {
var row = reportIter.next();
if(!row.DestinationUrl) { continue; }
var rowKey = [row.AdGroupId,row.Id].join('-');
if(kwsAlreadyChecked[rowKey]) { continue; }
row['rowKey'] = rowKey;
results[rowKey] = row;
}

return results;
}

function getRegexMatches(regex, string) {
if(!(regex instanceof RegExp)) {
return "ERROR";
}
else {
if (!regex.global) {
// If global flag not set, create new one.
var flags = "g";
if (regex.ignoreCase) flags += "i";
if (regex.multiline) flags += "m";
if (regex.sticky) flags += "y";
regex = RegExp(regex.source, flags);
}
}
var matches = [];
var match = regex.exec(string);
while (match) {
if (match.length > 2) {
var group_matches = [];
for (var i = 1; i < match.length; i++) {
group_matches.push(match[i]);
}
matches.push(group_matches);
}
else {
matches.push(match[1]);
}
match = regex.exec(string);
}

return matches;
}


function writeJSONFile(fileName,toWrite) {
var file = getFile(fileName);
try {
file.setContent(JSON.stringify(toWrite));
} catch(e) {
Logger.log('Cannot store data. File exceeding max size');
}
}

function readJSONFile(fileName) {
var file = getFile(fileName);
var fileData = file.getBlob().getDataAsString();
if(fileData) {
return JSON.parse(fileData);
} else {
return null;
}
}


function getFile(fileName) {
var errorCount = 3;
var errors = [];
while(errorCount > 0) {
try {
var filePath;
var localFileName;
var folder;
var fileIter;
if(fileName.indexOf('/')>=0) {
filePath = fileName.split('/').slice(0,-1).join('/');
localFileName = fileName.split('/').pop();
folder = createFolderPath(filePath);
fileIter = folder.getFilesByName(localFileName);
} else {
filePath = '';
localFileName = fileName;
fileIter = DriveApp.getFilesByName(localFileName);
}

if(!fileIter.hasNext()) {
var file = (folder) ? folder.createFile(localFileName,'') : DriveApp.createFile(localFileName,'');
return file;
} else {
return fileIter.next();
}
} catch (e) {
errorCount--;
errors.push(e);
Utilities.sleep(1000);
}
}
throw errors.join('\n');
}


function createFolderPath(folderPath) {
var errorCount = 3;
var errors = [];
while(errorCount > 0) {
try {
var pathArray = folderPath.split('/');
var folder;
for(var i in pathArray) {
var parentName = pathArray[i];
if(!parentName || parentName === '') { continue; }
if(!folder && !DriveApp.getFoldersByName(parentName).hasNext()) {
folder = DriveApp.createFolder(parentName);
} else if(folder && !folder.getFoldersByName(parentName).hasNext()) {
folder = folder.createFolder(parentName);
} else {
folder = (!folder) ? DriveApp.getFoldersByName(parentName).next() : folder.getFoldersByName(parentName).next();
}
}
return folder;
} catch (e) {
errorCount--;
errors.push(e);
Utilities.sleep(1000);
}
}
throw errors.join('\n');
}

function finishedToday() {
var dateStr = Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), 'yyyy-MM-dd');
var finishedLabelName = PREFIX+dateStr;
var alreadyDone = AdWordsApp.labels().withCondition("Name = '"+finishedLabelName+"'").get().hasNext();
if(alreadyDone) {
Logger.log('All keywords have been updated for today.');
return true;
}
return false;
}

function clearCompletedLabel() {
var labelIter = AdWordsApp.labels().withCondition("Name STARTS_WITH '"+PREFIX+"'").get();
while(labelIter.hasNext()) { labelIter.next().remove(); }
}

function shouldExitNow() {
return (AdWordsApp.getExecutionInfo().getRemainingTime() < (60*6));
}

function shouldExitRightNow() {
return (AdWordsApp.getExecutionInfo().getRemainingTime() < (60*4));
}

function debug(msg) {
var time = Utilities.formatDate(new Date(),AdWordsApp.currentAccount().getTimeZone(),'yyyy-MM-dd HH:mm:ss.SSS');
Logger.log(time + ' - ' + AdWordsApp.currentAccount().getName() + ': ' + msg);
}

function getCampaignsByLabel(label) {
var ids = [];
if(!label) { return ids; }
if(!labelExists(label)) { return ids; }
var camps = AdWordsApp.campaigns().withCondition('Status = ENABLED').withCondition('LabelNames CONTAINS_ANY ["' + label + '"]').get();
while(camps.hasNext()){
ids.push(camps.next().getId());
}
return ids;
}

function labelExists(label) {
return AdWordsApp.labels().withCondition('Name = "' + label + '"').get().hasNext();
}