@pipedream/google_ads 0.0.3 → 0.1.1

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.
@@ -0,0 +1,64 @@
1
+ import crypto from "crypto";
2
+ import googleAds from "../../google_ads.app.mjs";
3
+
4
+ export default {
5
+ key: "google_ads-add-contact-to-list-by-email",
6
+ name: "Add Contact to Customer List by Email",
7
+ 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)",
8
+ version: "0.0.2",
9
+ type: "action",
10
+ props: {
11
+ googleAds,
12
+ contactEmail: {
13
+ propDefinition: [
14
+ googleAds,
15
+ "contactEmail",
16
+ ],
17
+ },
18
+ userListId: {
19
+ propDefinition: [
20
+ googleAds,
21
+ "userListId",
22
+ ],
23
+ },
24
+ },
25
+ async run({ $ }) {
26
+ const offlineUserDataJob = await this.googleAds.createOfflineUserDataJob({
27
+ data: {
28
+ job: {
29
+ customerMatchUserListMetadata: {
30
+ userList: `customers/${this.googleAds.$auth.login_customer_id}/userLists/${this.userListId}`,
31
+ },
32
+ type: "CUSTOMER_MATCH_USER_LIST",
33
+ },
34
+ },
35
+ });
36
+
37
+ await this.googleAds.addContactToCustomerList({
38
+ $,
39
+ path: offlineUserDataJob.resourceName,
40
+ data: {
41
+ operations: [
42
+ {
43
+ create: {
44
+ userIdentifiers: [
45
+ {
46
+ hashedEmail: crypto.createHash("sha256").update(this.contactEmail)
47
+ .digest("hex"),
48
+ },
49
+ ],
50
+ },
51
+ },
52
+ ],
53
+ },
54
+ });
55
+
56
+ const response = await this.googleAds.runOfflineUserDataJob({
57
+ $,
58
+ path: offlineUserDataJob.resourceName,
59
+ });
60
+
61
+ $.export("$summary", `Added contact ${this.contactEmail} to the user list ${this.userListId}`);
62
+ return response;
63
+ },
64
+ };
@@ -0,0 +1,86 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "google_ads",
6
+ propDefinitions: {
7
+ contactEmail: {
8
+ type: "string",
9
+ label: "Contact Email",
10
+ description: "Email address of the contact to add to the customer list.",
11
+ },
12
+ userListId: {
13
+ type: "string",
14
+ label: "User List ID",
15
+ description: "The ID of the user list to add the contact to.",
16
+ async options() {
17
+ const { results = [] } = await this.listLists();
18
+
19
+ return results.map(({
20
+ userList: {
21
+ id: value, name: label,
22
+ },
23
+ }) => ({
24
+ label,
25
+ value,
26
+ }));
27
+ },
28
+ },
29
+ },
30
+ methods: {
31
+ _baseUrl() {
32
+ return "https://eolid4dq1k0t9hi.m.pipedream.net";
33
+ },
34
+ _headers() {
35
+ return {
36
+ "Authorization": `Bearer ${this.$auth.oauth_access_token}`,
37
+ };
38
+ },
39
+ _makeRequest({
40
+ $ = this, ...opts
41
+ }) {
42
+ const googleAdsRequest = {
43
+ headers: this._headers(),
44
+ ...opts,
45
+ };
46
+ return axios($, {
47
+ url: this._baseUrl(),
48
+ data: googleAdsRequest,
49
+ });
50
+ },
51
+ addContactToCustomerList({
52
+ path, ...opts
53
+ }) {
54
+ return this._makeRequest({
55
+ method: "POST",
56
+ path: `/v15/${path}:addOperations`,
57
+ ...opts,
58
+ });
59
+ },
60
+ createOfflineUserDataJob(opts = {}) {
61
+ return this._makeRequest({
62
+ method: "POST",
63
+ path: `/v15/customers/${this.$auth.login_customer_id}/offlineUserDataJobs:create`,
64
+ ...opts,
65
+ });
66
+ },
67
+ runOfflineUserDataJob({ path }) {
68
+ return this._makeRequest({
69
+ method: "POST",
70
+ path: `/v15/${path}:run`,
71
+ });
72
+ },
73
+ listLists() {
74
+ return this._makeRequest({
75
+ method: "POST",
76
+ path: `/v15/customers/${this.$auth.login_customer_id}/googleAds:search`,
77
+ data: {
78
+ query: `SELECT
79
+ user_list.id,
80
+ user_list.name
81
+ FROM user_list`,
82
+ },
83
+ });
84
+ },
85
+ },
86
+ };
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@pipedream/google_ads",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "description": "Pipedream Google Ads Components",
5
- "main": "dist/app/google_ads.app.mjs",
5
+ "main": "google_ads.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "google_ads"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/google_ads",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
16
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1",
17
+ "crypto": "^1.0.1"
17
18
  }
18
19
  }