Tag Archives: mysql

AdWords to MySQL

Posted on by .

Did you know it’s possible to write AdWords data directly to a database (Google Cloud SQL, MySQL, SQL Server, etc.)? I’ve seen little mention of it, but Google announced in March that JDBC is now supported in AdWords Scripts.

Here’s an example for how to write your complete list of AdWords Keywords into a table on Google Cloud SQL (MySql). Please note: I am not a programmer. I simply modify example code to accomplish what I want. There very well could be a better, faster, more secure way to perform the same function.

CODE

//Get list of Keywords
var report = AdWordsApp.report(
'SELECT ExternalCustomerId, CampaignId, AdGroupId, Id, KeywordText, KeywordMatchType, 
FinalUrls ' +
'FROM KEYWORDS_PERFORMANCE_REPORT'); 

//Connect to Database
var conn = Jdbc.getConnection(dbUrl, user, userPwd);
conn.setAutoCommit(false);

//Update Keyword Table 
var stmt = conn.prepareStatement('REPLACE INTO KEYWORDS '
 + '(ExternalCustomerId, CampaignId, AdGroupId, KeywordId, KeywordText, 
KeywordMatchType, FinalUrls) values (?, ?, ?, ?, ?, ?, ?)');
 
var rows = report.rows(); 
 while (rows.hasNext()) {
 var row = rows.next();
 
 stmt.setLong(1, row["ExternalCustomerId"]);
 stmt.setLong(2, row["CampaignId"]);
 stmt.setLong(3, row["AdGroupId"]);
 stmt.setLong(4, row["Id"]);
 stmt.setString(5, row["KeywordText"]);
 stmt.setString(6, row["KeywordMatchType"]);
 stmt.setString(7, row["FinalUrls"]);
 stmt.addBatch();
 }

 var batch = stmt.executeBatch();
 conn.commit();
 conn.close();

END CODE

Instead of using third party programs, importing data from downloaded reports or using convoluted php scripts, you can use relatively simple AdWords Scripts and automate the process. The example above was simply for a list of Keywords, but think of all the data available
in AdWords Scripts and having access to that in your own database!

For more details on using JDBC with AdWords Scripts, please see Apps Script Developers Guide.

 

 

Related Posts:

  • No Related Posts