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

How to import AdWords data to MySQL?

Explorer ✭ ✭ ☆
# 1
Explorer ✭ ✭ ☆

Hello,

 

  1. What is the best way to import AdWords data to MySQL?
  2. How can I automatize this process (update data everyday)?

 

Thanks,

 

- Lukas
2 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Lukas Melichar
September 2015

Re: How to import AdWords data to MySQL?

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

Hi Lukas,

 

Some time ago we wrote a small script for sending data to url address where a php script inserts the data into mySQL. For security the folder is with robots.txt and there is a code passed as a identifier for identity. This way it may have problems if the data is too much.

 

here it is:

 

function main() {
getKeywordPerformanceReport2();
}

function putDataToBucket(campaign,stats,clientid) {

var curl = 'http://www.yoursite.com/data/populate.php'
+ '?cid=' + clientid
+ '&ccode=securityCODE'
+ '&name=' + campaign.getName()
+ '&budj=' + campaign.getBudget()
+ '&clicks=' + stats.getClicks()
+ '&cpc=' + stats.getAverageCpc()
+ '&ctr=' + stats.getCtr()
+ '&cpm=' + stats.getAverageCpm()
+ '&pos=' + stats.getAveragePosition()
+ '&cov=' + stats.getConversions()
+ '&covrate=' + stats.getConversionRate()
+ '&cost=' + stats.getCost()
+ '&impr=' + stats.getImpressions();

UrlFetchApp.fetch(curl);
}

function getKeywordPerformanceReport() {
/* ======================= SETTINGS ====================== */
var date_range = 'LAST_7_DAYS';
var clientid = 17;
/* ======================= SETTINGS END ====================== */
var campaignsIterator = AdWordsApp.campaigns()
.withCondition("Impressions > 10")
.forDateRange(date_range)
.get();

var campaign = campaignsIterator.next();
var stats = campaign.getStatsFor(date_range);
putDataToBucket(campaign,stats,clientid);


return campaign;
}

function getKeywordPerformanceReport2() {
/* ======================= SETTINGS ====================== */
var date_range = 'LAST_7_DAYS';
var clientid = profileID;
/* ======================= SETTINGS END ====================== */
/* ======================= PARAMS ====================== */
var iterations = 0;
var clicks = 0;
var budjet = 0;
var avgCPC = 0;
var avgCtr = 0;
var AverageCpm = 0;
var avgPos = 0;
var conv = 0;
var convrate = 0;
var cost = 0;
var impr = 0;
/* ======================= PARAMS END ====================== */

var campaignsIterator = AdWordsApp.campaigns()
.withCondition("Impressions > 10")
.forDateRange(date_range)
.get();

while (campaignsIterator.hasNext()) {
var campaign = campaignsIterator.next();
var stats = campaign.getStatsFor(date_range);

iterations = iterations + 1;
clicks = clicks + stats.getClicks();
budjet = budjet + campaign.getBudget();
avgCPC = avgCPC + stats.getAverageCpc();
avgCtr = avgCtr + stats.getCtr();
AverageCpm = AverageCpm + stats.getAverageCpm();
avgPos = avgPos + stats.getAveragePosition();
conv = conv + stats.getConversions();
convrate = convrate + stats.getConversionRate();
cost = cost + stats.getCost();
impr = impr + stats.getImpressions();
}

avgCPC = avgCPC/iterations;
avgCtr = avgCtr/iterations;
AverageCpm = AverageCpm/iterations;
avgPos = avgPos/iterations;
convrate = convrate/iterations;


var curl = 'http://www.yoursite.com/data/populate.php'
+ '?cid=' + clientid
+ '&ccode=securtyCODE'
+ '&name=' + campaign.getName()
+ '&budj=' + budjet
+ '&clicks=' + clicks
+ '&cpc=' + avgCPC
+ '&ctr=' + avgCtr
+ '&cpm=' + AverageCpm
+ '&pos=' + avgPos
+ '&cov=' + conv
+ '&covrate=' + convrate
+ '&cost=' + cost
+ '&impr=' + impr

UrlFetchApp.fetch(curl);


return campaign;
}

Re: How to import AdWords data to MySQL?

Explorer ✭ ✭ ☆
# 3
Explorer ✭ ✭ ☆
is there any page where I can find out more about AdWords and MySQL? Thanks
- Lukas
Marked as Best Answer.
Solution
Accepted by topic author Lukas Melichar
September 2015

Re: How to import AdWords data to MySQL?

Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆
Here there are a lot of good scripts for adwords, but probably you need to correct them a little bit:
http://www.freeadwordsscripts.com/

I can't give you page exacly for adwords and mysql

Re: How to import AdWords data to MySQL?

Explorer ✭ ✭ ☆
# 5
Explorer ✭ ✭ ☆
Thank you Венелин and if anyone else has a comment, please, feel free to post it Smiley Happy
- Lukas
Marked as Best Answer.
Solution
Accepted by topic author Lukas Melichar
September 2015

Re: How to import AdWords data to MySQL?

Top Contributor
# 6
Top Contributor

Hi Lukas, 


Scripts don't yet (and I hope it is a yet, not a "never will") support writing to external databases so using a POST to a webpage as described by Venelin is about as good as you can get at the moment and at least that can easily be scheduled.  There are other methods, but I don't think any will be as easy to automate.  The key problem with Venelin's method is that it'll fall over when you have a large number of elements.

 

There really are no pages about AdWords and MySQL because there's no direct way of connecting them at present.

 

Jon

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

How to import AdWords data to MySQL?

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hi Lukas,

 

Instead of importing data into MySQL, you can setup an adwords script that runs regularly to export data into MySQL via Google Scripts & JDBC.

As the script is run directly in your account, you won't have to bother with connections and API keys to connect to Adwords.

Under "Bulk Operations->Scripts" you can quickly setup queries with AWQL and use a JDBC connection to insert data to a MySQL server

 

Script reference - https://support.google.com/adwords/answer/188712?hl=en

AWQL Reference - https://developers.google.com/adwords/api/docs/guides/awql

JDBC Conn Reference - https://developers.google.com/apps-script/guides/jdbc

 

Hope it helps

Lourenco

How to import AdWords data to MySQL?

Top Contributor
# 8
Top Contributor

This thread has been closed to new replies.

If you have a new or unanswered question related to this topic, please start a new thread and post a clear, specific and detailed question that describes your particular situation.

To start a new thread, please go to the top level of the Community, and from there, click on the board that is most closely related to your question. After that, you can click on the pink "+" sign in the lower right corner of the screen to start a new topic.

Thank you.

Moshe, AdWords Top Contributor , Twitter | Linkedin | Community Profile | Ad-Globe
Did you find any helpful responses or answers to your query? If yes, please mark it as the ‘Best Answer’