Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Ads - Create Report improvement #12519

Merged
merged 20 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "google_ads-add-contact-to-list-by-email",
name: "Add Contact to Customer List by Email",
description: "Adds a contact to a specific customer list in Google Ads. Lists typically update in 6 to 12 hours after operation. [See the documentation](https://developers.google.com/google-ads/api/docs/remarketing/audience-segments/customer-match/get-started)",
version: "0.1.0",
version: "0.1.1",
type: "action",
props: {
...common.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
name: "Create Customer List",
description:
"Create a new customer list in Google Ads. [See the documentation](https://developers.google.com/google-ads/api/rest/reference/rest/v16/UserList)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
...common.props,
Expand Down
55 changes: 55 additions & 0 deletions components/google_ads/actions/create-report/common-constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const DATE_RANGE_OPTIONS = [
{
value: "CUSTOM",
label: "Specify a custom date range",
},
{
value: "TODAY",
label: "Today only",
},
{
value: "YESTERDAY",
label: "Yesterday only",
},
{
value: "LAST_7_DAYS",
label: "The last 7 days not including today",
},
{
value: "LAST_BUSINESS_WEEK",
label:
"The 5 day business week, Monday through Friday, of the previous business week",
},
{
value: "THIS_MONTH",
label: "All days in the current month",
},
{
value: "LAST_MONTH",
label: "All days in the previous month",
},
{
value: "LAST_14_DAYS",
label: "The last 14 days not including today",
},
{
value: "LAST_30_DAYS",
label: "The last 30 days not including today",
},
{
value: "THIS_WEEK_SUN_TODAY",
label: "The period between the previous Sunday and the current day",
},
{
value: "THIS_WEEK_MON_TODAY",
label: "The period between the previous Monday and the current day",
},
{
value: "LAST_WEEK_SUN_SAT",
label: "The 7-day period starting with the previous Sunday",
},
{
value: "LAST_WEEK_MON_SUN",
label: "The 7-day period starting with the previous Monday",
},
];
96 changes: 91 additions & 5 deletions components/google_ads/actions/create-report/create-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ad } from "../../common/resources/ad.mjs";
import { campaign } from "../../common/resources/campaign.mjs";
import { customer } from "../../common/resources/customer.mjs";
import { ConfigurationError } from "@pipedream/platform";
import { DATE_RANGE_OPTIONS } from "./common-constants.mjs";

const RESOURCES = [
adGroup,
Expand All @@ -17,7 +18,7 @@ export default {
key: "google_ads-create-report",
name: "Create Report",
description: "Generates a report from your Google Ads data. [See the documentation](https://developers.google.com/google-ads/api/fields/v16/overview)",
version: "0.0.2",
version: "0.1.0",
type: "action",
props: {
...common.props,
Expand All @@ -43,26 +44,64 @@ export default {
alertType: "info",
content: `[See the documentation](https://developers.google.com/google-ads/api/fields/v16/${value}) for more information on available fields, segments and metrics.`,
},
objectFilter: {
type: "string[]",
label: `Filter by ${label}s`,
description: `Select the ${label}s to generate a report for (or leave blank for all ${label}s)`,
optional: true,
options: async () => {
const {
accountId, customerClientId, resource,
} = this;
const items = await this.googleAds.listResources({
accountId,
customerClientId,
resource,
});
console.log(items);
return items?.map?.((item) => this.getResourceOption(item, resource));
},
},
dateRange: {
type: "string",
label: "Date Range",
description: "Select a date range for the report",
options: DATE_RANGE_OPTIONS,
optional: true,
reloadProps: true,
},
...(this.dateRange === "CUSTOM" && {
startDate: {
type: "string",
label: "Start Date",
description: "The start date, in `YYYY-MM-DD` format",
},
endDate: {
type: "string",
label: "End Date",
description: "The end date, in `YYYY-MM-DD` format",
},
}),
fields: {
type: "string[]",
label: "Fields",
description: `${label} data fields to obtain`,
description: "Select any fields you want to include in your report.",
options: resource.fields,
optional: true,
reloadProps: true,
},
segments: {
type: "string[]",
label: "Segments",
description: `${label} segments to obtain [more info on the documentation](https://developers.google.com/google-ads/api/fields/v16/segments)`,
description: "Select any segments you want to include in your report. See the documentation [here](https://developers.google.com/google-ads/api/fields/v16/segments)",
options: resource.segments,
optional: true,
reloadProps: true,
},
metrics: {
type: "string[]",
label: "Metrics",
description: `${label} metrics to obtain [more info on the documentation](https://developers.google.com/google-ads/api/fields/v16/metrics)`,
description: "Select any metrics you want to include in your report. See the documentation [here](https://developers.google.com/google-ads/api/fields/v16/metrics)",
options: resource.metrics,
optional: true,
reloadProps: true,
Expand Down Expand Up @@ -114,13 +153,47 @@ export default {
};
},
methods: {
getResourceOption(item, resource) {
let label, value;
switch (resource) {
case "campaign":
label = item.campaign.name;
value = item.campaign.id;
break;

case "customer":
label = item.customer.descriptiveName;
value = item.customer.id;
break;

case "ad_group":
label = item.adGroup.name;
value = item.adGroup.id;
break;

case "ad_group_ad":
label = item.adGroupAd.ad.name;
value = item.adGroupAd.ad.id;
break;
}

return {
label,
value,
};
},
buildQuery() {
const {
resource, limit, orderBy, direction,
resource, limit, orderBy, direction, objectFilter, dateRange,
} = this;
const fields = this.fields?.map((i) => `${resource}.${i}`) ?? [];
const segments = this.segments?.map((i) => `segments.${i}`) ?? [];
const metrics = this.metrics?.map((i) => `metrics.${i}`) ?? [];

if (dateRange && !segments.includes("segments.date")) {
segments.push("segments.date");
}

const selection = [
...fields,
...segments,
Expand All @@ -138,6 +211,19 @@ export default {
if (limit) {
query += ` LIMIT ${limit}`;
}
if (objectFilter) {
query += ` WHERE ${resource === "ad_group_ad"
? "ad_group_ad.ad"
: resource}.id IN (${objectFilter.join?.(", ") ?? objectFilter})`;
}
if (dateRange) {
const dateClause = dateRange === "CUSTOM"
? `BETWEEN '${this.startDate}' AND '${this.endDate}'`
: `DURING ${dateRange}`;
query += ` ${objectFilter
? "AND"
: "WHERE"} segments.date ${dateClause}`;
}

return query;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "google_ads-send-offline-conversion",
name: "Send Offline Conversion",
description: "Send an event from to Google Ads to track offline conversions. [See the documentation](https://developers.google.com/google-ads/api/rest/reference/rest/v16/ConversionAction)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
...common.props,
Expand Down
11 changes: 11 additions & 0 deletions components/google_ads/common/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,23 @@ function listCampaigns({
return `SELECT ${fields.map((s) => `campaign.${s}`).join(", ")} FROM campaign${filter}`;
}

function listResources(resource) {
const name = resource === "customer"
? "descriptive_name"
: "name";
const fieldResource = resource === "ad_group_ad"
? "ad_group_ad.ad"
: resource;
return `SELECT ${fieldResource}.id, ${fieldResource}.${name} FROM ${resource}`;
}

export const QUERIES = {
listCampaigns,
listConversionActions,
listCustomerClients,
listLeadForms,
listLeadFormSubmissionData,
listRemarketingActions,
listResources,
listUserLists,
};
7 changes: 0 additions & 7 deletions components/google_ads/common/resources/ad.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,13 @@ const segments = [
"conversion_adjustment",
"conversion_lag_bucket",
"conversion_or_adjustment_lag_bucket",
"date",
"day_of_week",
"device",
"external_conversion_source",
"keyword.ad_group_criterion",
"keyword.info.match_type",
"keyword.info.text",
"month",
"month_of_year",
"new_versus_returning_customers",
"quarter",
"slot",
"week",
"year",
];

const metrics = [
Expand Down
7 changes: 0 additions & 7 deletions components/google_ads/common/resources/adGroup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,11 @@ const segments = [
"conversion_adjustment",
"conversion_lag_bucket",
"conversion_or_adjustment_lag_bucket",
"date",
"day_of_week",
"device",
"external_conversion_source",
"hour",
"month",
"month_of_year",
"new_versus_returning_customers",
"quarter",
"slot",
"week",
"year",
];

const metrics = [
Expand Down
7 changes: 0 additions & 7 deletions components/google_ads/common/resources/campaign.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,10 @@ const segments = [
"conversion_lag_bucket",
"conversion_or_adjustment_lag_bucket",
"conversion_value_rule_primary_dimension",
"date",
"day_of_week",
"device",
"external_conversion_source",
"hour",
"month",
"month_of_year",
"new_versus_returning_customers",
"quarter",
"recommendation_type",
"sk_ad_network_ad_event_type",
"sk_ad_network_attribution_credit",
Expand All @@ -130,8 +125,6 @@ const segments = [
"sk_ad_network_source_type",
"sk_ad_network_user_type",
"slot",
"week",
"year",
];

const metrics = [
Expand Down
7 changes: 0 additions & 7 deletions components/google_ads/common/resources/customer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ const segments = [
"conversion_lag_bucket",
"conversion_or_adjustment_lag_bucket",
"conversion_value_rule_primary_dimension",
"date",
"day_of_week",
"device",
"external_conversion_source",
"hour",
"month",
"month_of_year",
"new_versus_returning_customers",
"quarter",
"recommendation_type",
"sk_ad_network_ad_event_type",
"sk_ad_network_attribution_credit",
Expand All @@ -65,8 +60,6 @@ const segments = [
"sk_ad_network_source_type",
"sk_ad_network_user_type",
"slot",
"week",
"year",
];

const metrics = [
Expand Down
8 changes: 8 additions & 0 deletions components/google_ads/google_ads.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ export default {
...args,
});
},
async listResources({
resource, ...args
}) {
return this.search({
query: QUERIES.listResources(resource),
...args,
});
},
async getLeadFormData({
leadFormId, ...args
}) {
Expand Down
2 changes: 1 addition & 1 deletion components/google_ads/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/google_ads",
"version": "0.2.1",
"version": "0.3.0",
"description": "Pipedream Google Ads Components",
"main": "google_ads.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "google_ads-new-campaign-created",
name: "New Campaign Created",
description: "Emit new event when a new campaign is created. [See the documentation](https://developers.google.com/google-ads/api/fields/v16/campaign)",
version: "0.0.1",
version: "0.0.2",
type: "source",
dedupe: "unique",
sampleEmit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "google_ads-new-lead-form-entry",
name: "New Lead Form Entry",
description: "Emit new event for new leads on a Lead Form. [See the documentation](https://developers.google.com/google-ads/api/fields/v16/lead_form_submission_data)",
version: "0.0.1",
version: "0.0.2",
type: "source",
dedupe: "unique",
sampleEmit,
Expand Down
Loading