@weppa-cloud/mcp-google-ads
Version:
Google Ads MCP server for growth marketing - campaign optimization, keyword research, and ROI tracking
56 lines • 1.81 kB
JavaScript
import { GoogleAdsApi } from 'google-ads-api';
export class GoogleAdsAuth {
client;
customerId;
refreshToken;
loginCustomerId;
constructor(config) {
this.customerId = config.customerId.replace(/-/g, ''); // Remove hyphens
this.refreshToken = config.refreshToken;
this.loginCustomerId = config.loginCustomerId?.replace(/-/g, '');
this.client = new GoogleAdsApi({
client_id: config.clientId,
client_secret: config.clientSecret,
developer_token: config.developerToken,
});
}
getClient() {
return this.client;
}
getCustomer() {
return this.client.Customer({
customer_id: this.customerId,
refresh_token: this.refreshToken,
login_customer_id: this.loginCustomerId,
});
}
getCustomerId() {
return this.customerId;
}
// Helper para queries GAQL
async query(gaql) {
const customer = this.getCustomer();
try {
const response = await customer.query(gaql);
return response;
}
catch (error) {
console.error('Google Ads API Error:', error);
throw new Error(`Failed to execute query: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
// Helper para obtener el período de tiempo predeterminado (últimos 30 días)
getDefaultDateRange() {
const endDate = new Date();
const startDate = new Date();
startDate.setDate(startDate.getDate() - 30);
return {
startDate: this.formatDate(startDate),
endDate: this.formatDate(endDate),
};
}
formatDate(date) {
return date.toISOString().split('T')[0];
}
}
//# sourceMappingURL=auth.js.map