Google Ads是一种广告平台,它允许广告主在Google搜索结果页面、YouTube、Google Display Network等广告网络上展示广告。使用Google Ads API可以通过编程方式访问和管理Google Ads账户。
要使用google-ads-node从Google广告中获得印象,首先需要确保以下几点:
接下来,可以按照以下步骤使用google-ads-node从Google广告中获得印象:
const { google } = require('googleapis');
const { googleAds } = require('google-ads-node');
const auth = new google.auth.GoogleAuth({
keyFile: 'path/to/keyfile.json',
scopes: ['https://www.googleapis.com/auth/adwords']
});
const client = new googleAds.GoogleAdsClient({
credentials: await auth.getClient(),
version: 'v8' // 根据需要选择适当的版本
});
const customerId = 'YOUR_CUSTOMER_ID';
const query = `
SELECT
campaign.id,
campaign.name,
ad_group.id,
ad_group.name,
ad_group_criterion.criterion_id,
ad_group_criterion.keyword.text,
metrics.impressions
FROM
keyword_view
WHERE
segments.date DURING LAST_7_DAYS
LIMIT
10
`;
const response = await client.service.googleAds.search(customerId, query);
const results = response.results;
results.forEach(result => {
const campaignId = result.campaign.id.value;
const campaignName = result.campaign.name.value;
const adGroupId = result.ad_group.id.value;
const adGroupName = result.ad_group.name.value;
const criterionId = result.ad_group_criterion.criterion_id.value;
const keywordText = result.ad_group_criterion.keyword.text.value;
const impressions = result.metrics.impressions.value;
console.log(`Campaign: ${campaignName} (ID: ${campaignId})`);
console.log(`Ad Group: ${adGroupName} (ID: ${adGroupId})`);
console.log(`Keyword: ${keywordText} (ID: ${criterionId})`);
console.log(`Impressions: ${impressions}`);
});
请注意,以上代码仅为示例,实际使用时需要根据具体需求进行修改和扩展。
推荐的腾讯云相关产品:腾讯云广告推广服务,该服务提供了广告投放、广告效果分析等功能,适用于各种广告主的需求。详情请参考腾讯云广告推广服务的产品介绍:腾讯云广告推广服务。
领取专属 10元无门槛券
手把手带您无忧上云