@google-cloud/nodejs-common 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -49
- package/bin/install_functions.sh +16 -5
- package/package.json +14 -14
- package/src/apis/ads_data_hub.js +4 -2
- package/src/apis/cloud_platform_apis.js +4 -4
- package/src/apis/doubleclick_bidmanager.js +21 -2
- package/src/apis/google_ads.js +98 -10
- package/src/apis/index.js +1 -1
- package/src/components/utils.js +1 -34
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# NodeJS Common Library
|
|
2
2
|
|
|
3
|
-
<!--* freshness: { owner: 'lushu' reviewed: '
|
|
3
|
+
<!--* freshness: { owner: 'lushu' reviewed: '2022-04-07' } *-->
|
|
4
4
|
|
|
5
5
|
A NodeJs common library for other projects, e.g. [GMP and Google Ads Connector]
|
|
6
6
|
and [Data Tasks Coordinator]. This library includes:
|
|
@@ -11,68 +11,65 @@ and [Data Tasks Coordinator]. This library includes:
|
|
|
11
11
|
1. Wrapper for some Google APIs for integration, mainly
|
|
12
12
|
for [GMP and Google Ads Connector]:
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
- Google Analytics data import
|
|
15
|
+
- Google Analytics measurement protocol
|
|
16
|
+
- Campaign Manager offline conversion upload
|
|
17
|
+
- Search Ads 360 conversions upload
|
|
18
|
+
- Google Ads click conversions upload
|
|
19
|
+
- Google Ads customer match upload
|
|
20
|
+
- Google Ads enhanced conversions upload
|
|
21
|
+
- Google Ads conversions scheduled uploads based on Google Sheets
|
|
22
|
+
- Measurement Protocol Google Analytics 4
|
|
22
23
|
|
|
23
24
|
1. Wrapper for some Google APIs for reporting, mainly
|
|
24
25
|
for [Data Tasks Coordinator]:
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
- Google Ads reporting
|
|
28
|
+
- Campaign Manager reporting
|
|
29
|
+
- Search Ads 360 reporting
|
|
30
|
+
- Display and Video 360 reporting
|
|
31
|
+
- YouTube Data API
|
|
32
|
+
- Ads Data Hub querying
|
|
32
33
|
|
|
33
34
|
1. Utilities wrapper class for Google Cloud Products:
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
- **Firestore Access Object**: Firestore has two modes which are excluded to
|
|
37
|
+
each other and can't be changed once selected in a Cloud Project[[2]].
|
|
38
|
+
This class, with its two successors offer a unified interface to operate
|
|
39
|
+
data objects on either Firestore or Datastore.
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
- **AutoMl Tables API**: Offers a unified entry to use this API based on
|
|
42
|
+
Google Cloud client library combined with REST requests to service
|
|
43
|
+
directly due to some functionalities missed in the client library.
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
- **Vertex AI API**: Offers a unified entry to use this API based on Google
|
|
46
|
+
Cloud client library.
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
- **Pub/Sub Utilities**: Offers utilities functions to create topics and
|
|
49
|
+
subscriptions for Pub/Sub, as well as the convenient way to publish a
|
|
50
|
+
message.
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
- **Storage Utilities**: Offers functions to manipulate the files on Cloud
|
|
53
|
+
Storage. The main functions are:
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
- Reading a given length (or slightly less) content without breaking a
|
|
56
|
+
line;
|
|
57
|
+
- Splitting a file into multiple files with the given length (or
|
|
58
|
+
slightly less) without breaking a line;
|
|
59
|
+
- Merging files into one file.
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
- **Cloud Scheduler Adapter**: A wrapper to pause and resume Cloud Scheduler
|
|
62
|
+
jobs.
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
- **Cloud Functions Adapter**: Cloud Functions have different parameters in
|
|
65
|
+
different environments, e.g. Node6 vs Node8[[1]]. This utility file offers
|
|
66
|
+
an adapter to wrap a Node8 Cloud Functions into Node6 and Node8 compatible
|
|
67
|
+
functions.
|
|
67
68
|
|
|
68
69
|
1. A share library for [Bash] to facilitate installation tasks.
|
|
69
70
|
|
|
70
|
-
[
|
|
71
|
-
|
|
72
|
-
[
|
|
73
|
-
|
|
74
|
-
[
|
|
75
|
-
|
|
76
|
-
[2]:https://cloud.google.com/datastore/docs/concepts/overview#comparison_with_traditional_databases
|
|
77
|
-
|
|
78
|
-
[Bash]:https://www.gnu.org/software/bash/
|
|
71
|
+
[gmp and google ads connector]: https://github.com/GoogleCloudPlatform/cloud-for-marketing/tree/master/marketing-analytics/activation/gmp-googleads-connector
|
|
72
|
+
[data tasks coordinator]: https://github.com/GoogleCloudPlatform/cloud-for-marketing/tree/master/marketing-analytics/activation/data-tasks-coordinator
|
|
73
|
+
[1]: https://cloud.google.com/functions/docs/writing/background#functions-writing-background-hello-pubsub-node8-10
|
|
74
|
+
[2]: https://cloud.google.com/datastore/docs/concepts/overview#comparison_with_traditional_databases
|
|
75
|
+
[bash]: https://www.gnu.org/software/bash/
|
package/bin/install_functions.sh
CHANGED
|
@@ -173,7 +173,7 @@ project ID: [${current_project}]"
|
|
|
173
173
|
project=${project:-"${current_project}"}
|
|
174
174
|
target_project=${project}
|
|
175
175
|
fi
|
|
176
|
-
if [[ -
|
|
176
|
+
if [[ -z ${current_project} || \
|
|
177
177
|
${current_project} != "${target_project}" ]];then
|
|
178
178
|
printf '%s' "Setting the Google Cloud project to [${target_project}]..."
|
|
179
179
|
gcloud config set project "${target_project}"
|
|
@@ -1337,10 +1337,13 @@ do_authentication(){
|
|
|
1337
1337
|
do_oauth(){
|
|
1338
1338
|
# Base url of Google OAuth service.
|
|
1339
1339
|
OAUTH_BASE_URL="https://accounts.google.com/o/oauth2/"
|
|
1340
|
+
# Redirect uri.
|
|
1341
|
+
# Must be the same for requests of authorization code and refresh token.
|
|
1342
|
+
REDIRECT_URI="http%3A//127.0.0.1%3A8887"
|
|
1340
1343
|
# Defaulat parameters of OAuth requests.
|
|
1341
1344
|
OAUTH_PARAMETERS=(
|
|
1342
1345
|
"access_type=offline"
|
|
1343
|
-
"redirect_uri
|
|
1346
|
+
"redirect_uri=${REDIRECT_URI}"
|
|
1344
1347
|
"response_type=code"
|
|
1345
1348
|
)
|
|
1346
1349
|
while [ ${#ENABLED_OAUTH_SCOPES[@]} -eq 0 ]; do
|
|
@@ -1409,18 +1412,26 @@ EOF
|
|
|
1409
1412
|
printf '%s\n' "3. Open the link in browser and finish authentication: \
|
|
1410
1413
|
${auth_url}"
|
|
1411
1414
|
cat <<EOF
|
|
1412
|
-
Note:
|
|
1415
|
+
Note:
|
|
1416
|
+
If the OAuth client is not for a native application, there will be an \
|
|
1413
1417
|
"Error 400: redirect_uri_mismatch" shown up on the page. In this case, press \
|
|
1414
1418
|
"Enter" to start again with a native application OAuth client ID.
|
|
1419
|
+
If there is no local web server serving at ${REDIRECT_URI}, the \
|
|
1420
|
+
succeeded OAuth flow will land the browser on an error page ("This site can't \
|
|
1421
|
+
be reached"). This is an expected behavior. Copy the whole URL and continue.
|
|
1422
|
+
|
|
1415
1423
|
EOF
|
|
1416
|
-
printf '%s' "4. Copy the authorization code
|
|
1424
|
+
printf '%s' "4. Copy the authorization code or complete url from browser \
|
|
1425
|
+
and paste here: "
|
|
1417
1426
|
read -r auth_code
|
|
1418
1427
|
if [[ -z ${auth_code} ]]; then
|
|
1419
1428
|
printf '%s\n\n' "No authorization code. Starting from beginning again..."
|
|
1420
1429
|
continue
|
|
1421
1430
|
fi
|
|
1431
|
+
auth_code=$(printf "%s" "${auth_code}" | sed 's/^.*code=//;s/&.*//')
|
|
1432
|
+
printf '%s\n' "Got authorization code: ${auth_code}"
|
|
1422
1433
|
auth_response=$(curl -s -d "code=${auth_code}" -d "client_id=${client_id}" \
|
|
1423
|
-
-d "grant_type=authorization_code" -d "redirect_uri
|
|
1434
|
+
-d "grant_type=authorization_code" -d "redirect_uri=${REDIRECT_URI}" \
|
|
1424
1435
|
-d "client_secret=${client_secret}" "${OAUTH_BASE_URL}token")
|
|
1425
1436
|
auth_error=$(node -e "console.log(!!JSON.parse(process.argv[1]).error)" \
|
|
1426
1437
|
"${auth_response}")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/nodejs-common",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A NodeJs common library for solutions based on Cloud Functions",
|
|
5
5
|
"author": "Google Inc.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -16,25 +16,25 @@
|
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/GoogleCloudPlatform/cloud-for-marketing/blob/master/marketing-analytics/activation/common-libs/nodejs-common/README.md",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@google-cloud/aiplatform": "^1.
|
|
20
|
-
"@google-cloud/automl": "^2.5.
|
|
21
|
-
"@google-cloud/bigquery": "^5.
|
|
19
|
+
"@google-cloud/aiplatform": "^1.19.0",
|
|
20
|
+
"@google-cloud/automl": "^2.5.2",
|
|
21
|
+
"@google-cloud/bigquery": "^5.12.0",
|
|
22
22
|
"@google-cloud/datastore": "^6.6.2",
|
|
23
|
-
"@google-cloud/firestore": "^
|
|
24
|
-
"@google-cloud/logging-winston": "^4.
|
|
25
|
-
"@google-cloud/pubsub": "^2.
|
|
26
|
-
"@google-cloud/storage": "^5.
|
|
23
|
+
"@google-cloud/firestore": "^5.0.2",
|
|
24
|
+
"@google-cloud/logging-winston": "^4.2.2",
|
|
25
|
+
"@google-cloud/pubsub": "^2.19.0",
|
|
26
|
+
"@google-cloud/storage": "^5.18.3",
|
|
27
27
|
"gaxios": "^4.3.2",
|
|
28
|
-
"google-ads-api": "^
|
|
29
|
-
"google-ads-node":
|
|
30
|
-
"google-auth-library": "^7.
|
|
31
|
-
"googleapis": "^
|
|
28
|
+
"google-ads-api": "^10.0.1",
|
|
29
|
+
"google-ads-node":"^8.0.1",
|
|
30
|
+
"google-auth-library": "^7.14.1",
|
|
31
|
+
"googleapis": "^100.0.0",
|
|
32
32
|
"soap": "^0.43.0",
|
|
33
|
-
"winston": "^3.
|
|
33
|
+
"winston": "^3.7.2",
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"jasmine": "^
|
|
37
|
+
"jasmine": "^4.0.2"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"test": "node node_modules/jasmine/bin/jasmine"
|
package/src/apis/ads_data_hub.js
CHANGED
|
@@ -37,9 +37,11 @@ class AdsDataHub {
|
|
|
37
37
|
*
|
|
38
38
|
* @param {GaxiosOptions|undefined=} options Used to setup for tests.
|
|
39
39
|
* @param {string|undefined=} customerId ADH customer id.
|
|
40
|
+
* @param {!Object<string,string>=} env The environment object to hold env
|
|
41
|
+
* variables.
|
|
40
42
|
*/
|
|
41
|
-
constructor(options, customerId = undefined) {
|
|
42
|
-
const authClient = new AuthClient(API_SCOPES);
|
|
43
|
+
constructor(options, customerId = undefined, env = process.env) {
|
|
44
|
+
const authClient = new AuthClient(API_SCOPES, env);
|
|
43
45
|
this.auth = authClient.getDefaultAuth();
|
|
44
46
|
/** @const{GaxiosOptions} */ this.options = options || {};
|
|
45
47
|
/** @const{string|undefined=} */ this.customerId = customerId;
|
|
@@ -32,11 +32,11 @@ const API_VERSION = 'v1';
|
|
|
32
32
|
* Google cloud client libraries.
|
|
33
33
|
*/
|
|
34
34
|
class CloudPlatformApis {
|
|
35
|
-
constructor(
|
|
35
|
+
constructor(env = process.env) {
|
|
36
36
|
/** @const {!AuthClient} */
|
|
37
|
-
const authClient = new AuthClient(API_SCOPES);
|
|
38
|
-
this.auth = authClient.
|
|
39
|
-
this.projectId =
|
|
37
|
+
const authClient = new AuthClient(API_SCOPES, env);
|
|
38
|
+
this.auth = authClient.getDefaultAuth();
|
|
39
|
+
this.projectId = env['GCP_PROJECT'];
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -56,8 +56,13 @@ let RequestBody;
|
|
|
56
56
|
* https://developers.google.com/bid-manager/how-tos/authorizing
|
|
57
57
|
*/
|
|
58
58
|
class DoubleClickBidManager {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
/**
|
|
60
|
+
* @constructor
|
|
61
|
+
* @param {!Object<string,string>=} env The environment object to hold env
|
|
62
|
+
* variables.
|
|
63
|
+
*/
|
|
64
|
+
constructor(env = process.env) {
|
|
65
|
+
const authClient = new AuthClient(API_SCOPES, env);
|
|
61
66
|
const auth = authClient.getDefaultAuth();
|
|
62
67
|
/** @const {!google.doubleclickbidmanager} */
|
|
63
68
|
this.instance = google.doubleclickbidmanager({
|
|
@@ -104,6 +109,20 @@ class DoubleClickBidManager {
|
|
|
104
109
|
return response.data.queryId;
|
|
105
110
|
}
|
|
106
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Deletes a query.
|
|
114
|
+
* @param {number} queryId
|
|
115
|
+
* @return {!Promise<boolean>} Whether the query was deleted.
|
|
116
|
+
*/
|
|
117
|
+
async deleteQuery(queryId) {
|
|
118
|
+
try {
|
|
119
|
+
await this.instance.queries.deletequery({ queryId });
|
|
120
|
+
return true;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error(error);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
107
126
|
}
|
|
108
127
|
|
|
109
128
|
module.exports = {
|
package/src/apis/google_ads.js
CHANGED
|
@@ -31,6 +31,8 @@ const {
|
|
|
31
31
|
services: {
|
|
32
32
|
UploadClickConversionsRequest,
|
|
33
33
|
UploadClickConversionsResponse,
|
|
34
|
+
UploadConversionAdjustmentsRequest,
|
|
35
|
+
UploadConversionAdjustmentsResponse,
|
|
34
36
|
UploadUserDataRequest,
|
|
35
37
|
UploadUserDataResponse,
|
|
36
38
|
UserDataOperation,
|
|
@@ -51,8 +53,9 @@ const API_SCOPES = Object.freeze(['https://www.googleapis.com/auth/adwords',]);
|
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* List of properties that will be taken from the data file as elements of a
|
|
54
|
-
* conversion.
|
|
56
|
+
* conversion or a conversion adjustment.
|
|
55
57
|
* @see https://developers.google.com/google-ads/api/reference/rpc/latest/ClickConversion
|
|
58
|
+
* @see https://developers.google.com/google-ads/api/reference/rpc/latest/ConversionAdjustment
|
|
56
59
|
* @type {Array<string>}
|
|
57
60
|
*/
|
|
58
61
|
const PICKED_PROPERTIES = [
|
|
@@ -65,6 +68,10 @@ const PICKED_PROPERTIES = [
|
|
|
65
68
|
'conversion_value',
|
|
66
69
|
'currency_code',
|
|
67
70
|
'order_id',
|
|
71
|
+
'adjustment_type',
|
|
72
|
+
'adjustment_date_time',
|
|
73
|
+
'user_agent',
|
|
74
|
+
'gclid_date_time_pair',
|
|
68
75
|
];
|
|
69
76
|
|
|
70
77
|
/**
|
|
@@ -88,9 +95,11 @@ const IDENTIFIERS = [
|
|
|
88
95
|
const MAX_IDENTIFIERS_PER_USER = 20;
|
|
89
96
|
|
|
90
97
|
/**
|
|
91
|
-
* Configuration for uploading click conversions
|
|
98
|
+
* Configuration for uploading click conversions or conversion adjustments for
|
|
99
|
+
* Google Ads, includes:
|
|
92
100
|
* gclid, conversion_action, conversion_date_time, conversion_value,
|
|
93
|
-
* currency_code, order_id, external_attribution_data,
|
|
101
|
+
* currency_code, order_id, external_attribution_data,
|
|
102
|
+
* adjustment_type, adjustment_date_time, user_agent, gclid_date_time_pair, etc.
|
|
94
103
|
* @see PICKED_PROPERTIES
|
|
95
104
|
*
|
|
96
105
|
* Other properties that will be used to build the conversions but not picked by
|
|
@@ -116,12 +125,15 @@ const MAX_IDENTIFIERS_PER_USER = 20;
|
|
|
116
125
|
* conversion_value: number,
|
|
117
126
|
* currency_code:(string|undefined),
|
|
118
127
|
* order_id: (string|undefined),
|
|
119
|
-
*
|
|
128
|
+
* adjustment_type: (string|undefined),
|
|
129
|
+
* adjustment_date_time: (!ConversionAdjustmentType|undefined),
|
|
130
|
+
* user_agent: (string|undefined),
|
|
131
|
+
* user_identifier_source:(!UserIdentifierSource|undefined),
|
|
120
132
|
* custom_variable_tags:(!Array<string>|undefined),
|
|
121
133
|
* customVariables:(!Object<string,string>|undefined),
|
|
122
134
|
* }}
|
|
123
135
|
*/
|
|
124
|
-
let
|
|
136
|
+
let ConversionConfig;
|
|
125
137
|
|
|
126
138
|
/**
|
|
127
139
|
* Configuration for uploading customer match to Google Ads, includes:
|
|
@@ -255,7 +267,7 @@ class GoogleAds {
|
|
|
255
267
|
* of click conversions.
|
|
256
268
|
* @param {string} customerId
|
|
257
269
|
* @param {string} loginCustomerId Login customer account ID (Mcc Account id).
|
|
258
|
-
* @param {!
|
|
270
|
+
* @param {!ConversionConfig} adsConfig Default click conversion params
|
|
259
271
|
* @return {!SendSingleBatch} Function which can send a batch of hits to
|
|
260
272
|
* Google Ads API.
|
|
261
273
|
*/
|
|
@@ -268,7 +280,7 @@ class GoogleAds {
|
|
|
268
280
|
* @return {!BatchResult}
|
|
269
281
|
*/
|
|
270
282
|
return async (lines, batchId) => {
|
|
271
|
-
/** @type {!Array<
|
|
283
|
+
/** @type {!Array<ConversionConfig>} */
|
|
272
284
|
const conversions = lines.map(
|
|
273
285
|
(line) => buildClickConversionFromLine(line, adsConfig, customerId));
|
|
274
286
|
/** @const {BatchResult} */
|
|
@@ -300,6 +312,57 @@ class GoogleAds {
|
|
|
300
312
|
}
|
|
301
313
|
}
|
|
302
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Returns the function to send out a request to Google Ads API with a batch
|
|
317
|
+
* of conversion adjustments.
|
|
318
|
+
* @param {string} customerId
|
|
319
|
+
* @param {string} loginCustomerId Login customer account ID (Mcc Account id).
|
|
320
|
+
* @param {!ConversionConfig} adsConfig Default conversion adjustments
|
|
321
|
+
* params.
|
|
322
|
+
* @return {!SendSingleBatch} Function which can send a batch of hits to
|
|
323
|
+
* Google Ads API.
|
|
324
|
+
*/
|
|
325
|
+
getUploadConversionAdjustmentFn(customerId, loginCustomerId, adsConfig) {
|
|
326
|
+
/**
|
|
327
|
+
* Sends a batch of hits to Google Ads API.
|
|
328
|
+
* @param {!Array<string>} lines Data for single request. It should be
|
|
329
|
+
* guaranteed that it doesn't exceed quota limitation.
|
|
330
|
+
* @param {string} batchId The tag for log.
|
|
331
|
+
* @return {!BatchResult}
|
|
332
|
+
*/
|
|
333
|
+
return async (lines, batchId) => {
|
|
334
|
+
/** @type {!Array<ConversionConfig>} */
|
|
335
|
+
const conversions = lines.map(
|
|
336
|
+
(line) => buildClickConversionFromLine(line, adsConfig, customerId));
|
|
337
|
+
/** @const {BatchResult} */
|
|
338
|
+
const batchResult = {
|
|
339
|
+
result: true,
|
|
340
|
+
numberOfLines: lines.length,
|
|
341
|
+
};
|
|
342
|
+
try {
|
|
343
|
+
const response = await this.uploadConversionAdjustments(conversions,
|
|
344
|
+
customerId, loginCustomerId);
|
|
345
|
+
const {results, partial_failure_error: failed} = response;
|
|
346
|
+
if (this.logger.isDebugEnabled()) {
|
|
347
|
+
const orderId = results.map((conversion) => conversion.order_id);
|
|
348
|
+
this.logger.debug('Uploaded order_id:', orderId);
|
|
349
|
+
}
|
|
350
|
+
if (failed) {
|
|
351
|
+
this.logger.info('partial_failure_error:', failed.message);
|
|
352
|
+
const failures = failed.details.map(
|
|
353
|
+
({value}) => GoogleAdsFailure.decode(value));
|
|
354
|
+
this.extraFailedLines_(batchResult, failures, lines, 0);
|
|
355
|
+
}
|
|
356
|
+
return batchResult;
|
|
357
|
+
} catch (error) {
|
|
358
|
+
this.logger.error(
|
|
359
|
+
`Error in upload conversion adjustments batch: ${batchId}`, error);
|
|
360
|
+
this.updateBatchResultWithError_(batchResult, error, lines, 0);
|
|
361
|
+
return batchResult;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
303
366
|
/**
|
|
304
367
|
* Updates the BatchResult based on errors.
|
|
305
368
|
*
|
|
@@ -434,7 +497,7 @@ class GoogleAds {
|
|
|
434
497
|
* Uploads click conversions to google ads account.
|
|
435
498
|
* It requires an array of click conversions and customer id.
|
|
436
499
|
* In DEBUG mode, this function will only validate the conversions.
|
|
437
|
-
* @param {Array<
|
|
500
|
+
* @param {Array<ConversionConfig>} clickConversions ClickConversions
|
|
438
501
|
* @param {string} customerId
|
|
439
502
|
* @param {string} loginCustomerId Login customer account ID (Mcc Account id).
|
|
440
503
|
* @return {!Promise<!UploadClickConversionsResponse>}
|
|
@@ -451,6 +514,31 @@ class GoogleAds {
|
|
|
451
514
|
return customer.conversionUploads.uploadClickConversions(request);
|
|
452
515
|
}
|
|
453
516
|
|
|
517
|
+
/**
|
|
518
|
+
* Uploads conversion adjustments to google ads account.
|
|
519
|
+
* It requires an array of conversion adjustments and customer id.
|
|
520
|
+
* In DEBUG mode, this function will only validate the conversion adjustments.
|
|
521
|
+
* @param {Array<ConversionAdjustment>} conversionAdjustments Conversion
|
|
522
|
+
* adjustments.
|
|
523
|
+
* @param {string} customerId
|
|
524
|
+
* @param {string} loginCustomerId Login customer account ID (Mcc Account id).
|
|
525
|
+
* @return {!Promise<!UploadConversionAdjustmentsResponse>}
|
|
526
|
+
*/
|
|
527
|
+
uploadConversionAdjustments(conversionAdjustments, customerId,
|
|
528
|
+
loginCustomerId) {
|
|
529
|
+
this.logger.debug('Upload conversion adjustments for customerId:',
|
|
530
|
+
customerId);
|
|
531
|
+
const customer = this.getGoogleAdsApiCustomer_(loginCustomerId, customerId);
|
|
532
|
+
const request = new UploadConversionAdjustmentsRequest({
|
|
533
|
+
conversion_adjustments: conversionAdjustments,
|
|
534
|
+
customer_id: customerId,
|
|
535
|
+
validate_only: this.debugMode, // when true makes no changes
|
|
536
|
+
partial_failure: true, // Will still create the non-failed entities
|
|
537
|
+
});
|
|
538
|
+
return customer.conversionAdjustmentUploads.uploadConversionAdjustments(
|
|
539
|
+
request);
|
|
540
|
+
}
|
|
541
|
+
|
|
454
542
|
/**
|
|
455
543
|
* Returns the id of Conversion Custom Variable with the given tag.
|
|
456
544
|
* @param {string} tag Custom Variable tag.
|
|
@@ -622,7 +710,7 @@ class GoogleAds {
|
|
|
622
710
|
/**
|
|
623
711
|
* Returns a conversion object based the given config and line data.
|
|
624
712
|
* @param {string} line A JSON string of a conversion data.
|
|
625
|
-
* @param {
|
|
713
|
+
* @param {ConversionConfig} config Default click conversion params
|
|
626
714
|
* @param {string} customerId
|
|
627
715
|
* @return {object} A conversion
|
|
628
716
|
*/
|
|
@@ -657,7 +745,7 @@ const buildClickConversionFromLine = (line, config, customerId) => {
|
|
|
657
745
|
}
|
|
658
746
|
|
|
659
747
|
module.exports = {
|
|
660
|
-
|
|
748
|
+
ConversionConfig,
|
|
661
749
|
CustomerMatchRecord,
|
|
662
750
|
CustomerMatchConfig,
|
|
663
751
|
GoogleAds,
|
package/src/apis/index.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.bigquery = require('./bigquery.js');
|
|
|
88
88
|
* APIs integration class for Google Ads.
|
|
89
89
|
* @const {{
|
|
90
90
|
* GoogleAds:!GoogleAds,
|
|
91
|
-
*
|
|
91
|
+
* ConversionConfig:!ConversionConfig,
|
|
92
92
|
* CustomerMatchConfig: !CustomerMatchConfig,
|
|
93
93
|
* CustomerMatchRecord: !CustomerMatchRecord,
|
|
94
94
|
* ReportQueryConfig:!ReportQueryConfig,
|
package/src/components/utils.js
CHANGED
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
const winston = require('winston');
|
|
22
22
|
const {inspect} = require('util');
|
|
23
|
-
const {LoggingWinston} = require('@google-cloud/logging-winston');
|
|
24
|
-
const {CloudPlatformApis} = require('../apis/cloud_platform_apis.js');
|
|
23
|
+
const { LoggingWinston } = require('@google-cloud/logging-winston');
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* The result of a batch of data sent to target API. The batch here means the
|
|
@@ -498,37 +497,6 @@ const extractObject = (paths) => {
|
|
|
498
497
|
};
|
|
499
498
|
};
|
|
500
499
|
|
|
501
|
-
/**
|
|
502
|
-
* Checks whether the permissions are granted for current authentication.
|
|
503
|
-
* This function will be invoked during the deployment of a specific solution,
|
|
504
|
-
* e.g. Tentacles, to make sure the operator has the proper permissions to
|
|
505
|
-
* carry on. If the operator doesn't have enough permissions, it will exit with
|
|
506
|
-
* status code 1 to let the invoker (the Bash installation script) know that it
|
|
507
|
-
* doesn't pass.
|
|
508
|
-
* @param {!Array<string>} permissions Array of permissions to check.
|
|
509
|
-
* @param {string} projectId The Id of Cloud project.
|
|
510
|
-
* @return {!Promise<undefined>}
|
|
511
|
-
*/
|
|
512
|
-
const checkPermissions = (permissions,
|
|
513
|
-
projectId = process.env['GCP_PROJECT']) => {
|
|
514
|
-
const cloudPlatformApis = new CloudPlatformApis(projectId);
|
|
515
|
-
return cloudPlatformApis.testIamPermissions(permissions)
|
|
516
|
-
.then((grantedPermissions) => {
|
|
517
|
-
console.log(grantedPermissions);
|
|
518
|
-
grantedPermissions = grantedPermissions || [];
|
|
519
|
-
if (grantedPermissions.length < permissions.length) {
|
|
520
|
-
const missedPermissions = permissions.filter(
|
|
521
|
-
(permission) => grantedPermissions.indexOf(permission) === -1);
|
|
522
|
-
console.error(`[MISSED] ${missedPermissions.join(',')}.`);
|
|
523
|
-
process.exit(1);
|
|
524
|
-
}
|
|
525
|
-
})
|
|
526
|
-
.catch((error) => {
|
|
527
|
-
console.error(`[ERROR] ${error.message}`);
|
|
528
|
-
process.exit(1);
|
|
529
|
-
});
|
|
530
|
-
};
|
|
531
|
-
|
|
532
500
|
/**
|
|
533
501
|
* For more details, see:
|
|
534
502
|
* https://developers.google.com/google-ads/api/docs/rest/design/json-mappings
|
|
@@ -565,7 +533,6 @@ module.exports = {
|
|
|
565
533
|
replaceParameters,
|
|
566
534
|
getFilterFunction,
|
|
567
535
|
extractObject,
|
|
568
|
-
checkPermissions,
|
|
569
536
|
changeNamingFromSnakeToUpperCamel,
|
|
570
537
|
changeNamingFromSnakeToLowerCamel,
|
|
571
538
|
};
|