@pipedream/google_ads 0.0.3 → 0.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.
@@ -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.1",
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,84 @@
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://googleads.googleapis.com";
33
+ },
34
+ _headers() {
35
+ return {
36
+ "Authorization": `Bearer ${this.$auth.oauth_access_token}`,
37
+ "developer-token": `${this.$auth.developer_token}`,
38
+ };
39
+ },
40
+ _makeRequest({
41
+ $ = this, path, ...opts
42
+ }) {
43
+ return axios($, {
44
+ url: this._baseUrl() + path,
45
+ headers: this._headers(),
46
+ ...opts,
47
+ });
48
+ },
49
+ addContactToCustomerList({
50
+ path, ...opts
51
+ }) {
52
+ return this._makeRequest({
53
+ method: "POST",
54
+ path: `/v15/${path}:addOperations`,
55
+ ...opts,
56
+ });
57
+ },
58
+ createOfflineUserDataJob(opts = {}) {
59
+ return this._makeRequest({
60
+ method: "POST",
61
+ path: `/v15/customers/${this.$auth.login_customer_id}/offlineUserDataJobs:create`,
62
+ ...opts,
63
+ });
64
+ },
65
+ runOfflineUserDataJob({ path }) {
66
+ return this._makeRequest({
67
+ method: "POST",
68
+ path: `/v15/${path}:run`,
69
+ });
70
+ },
71
+ listLists() {
72
+ return this._makeRequest({
73
+ method: "POST",
74
+ path: `/v15/customers/${this.$auth.login_customer_id}/googleAds:search`,
75
+ data: {
76
+ query: `SELECT
77
+ user_list.id,
78
+ user_list.name
79
+ FROM user_list`,
80
+ },
81
+ });
82
+ },
83
+ },
84
+ };
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.0",
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
  }