-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(cdp): support nested google ad accounts #28531
Open
MarconLP
wants to merge
19
commits into
master
Choose a base branch
from
google-ads-nested-accounts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−33
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2af4e76
support nested accounts
MarconLP 6fd8fd1
Merge branch 'master' into google-ads-nested-accounts
MarconLP 6a07804
Update UI snapshots for `chromium` (2)
github-actions[bot] d5a95d6
remove merge conflict
MarconLP a515d8e
resolve merge conflict
MarconLP 02d7087
resolve merge conflict
MarconLP e805f33
Merge branch 'master' into google-ads-nested-accounts
MarconLP 9f8bc34
Update UI snapshots for `chromium` (2)
github-actions[bot] 380db1e
update failing test
MarconLP 4657afc
fix type issue
MarconLP 87f44ce
fix python type
MarconLP 0a5d57a
fix api type
MarconLP a5101af
resolve conflict
MarconLP c31c40d
Update UI snapshots for `chromium` (2)
github-actions[bot] 480d671
remove snapshot
MarconLP ccc602f
Update UI snapshots for `chromium` (2)
github-actions[bot] fc04461
use params object instead
MarconLP e17925e
remove redundant code
MarconLP 3f9e5a8
remove snapshots
MarconLP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+33 Bytes
(100%)
frontend/__snapshots__/replay-player-success--recent-recordings--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10 Bytes
(100%)
frontend/__snapshots__/replay-player-success--recent-recordings--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,7 +481,7 @@ def __init__(self, integration: Integration) -> None: | |
def client(self) -> WebClient: | ||
return WebClient(self.integration.sensitive_config["access_token"]) | ||
|
||
def list_google_ads_conversion_actions(self, customer_id) -> list[dict]: | ||
def list_google_ads_conversion_actions(self, customer_id, parent_id=None) -> list[dict]: | ||
response = requests.request( | ||
"POST", | ||
f"https://googleads.googleapis.com/v18/customers/{customer_id}/googleAds:searchStream", | ||
|
@@ -490,6 +490,7 @@ def list_google_ads_conversion_actions(self, customer_id) -> list[dict]: | |
"Content-Type": "application/json", | ||
"Authorization": f"Bearer {self.integration.sensitive_config['access_token']}", | ||
"developer-token": settings.GOOGLE_ADS_DEVELOPER_TOKEN, | ||
**({"login-customer-id": parent_id} if parent_id else {}), | ||
}, | ||
) | ||
|
||
|
@@ -501,6 +502,8 @@ def list_google_ads_conversion_actions(self, customer_id) -> list[dict]: | |
|
||
return response.json() | ||
|
||
# Google Ads manager accounts can have access to other accounts (including other manager accounts). | ||
# Filter out duplicates where a user has direct access and access through a manager account, while prioritizing direct access. | ||
def list_google_ads_accessible_accounts(self) -> list[dict[str, str]]: | ||
response = requests.request( | ||
"GET", | ||
|
@@ -516,35 +519,65 @@ def list_google_ads_accessible_accounts(self) -> list[dict[str, str]]: | |
capture_exception(Exception(f"GoogleAdsIntegration: Failed to list accessible accounts: {response.text}")) | ||
raise Exception(f"There was an internal error") | ||
|
||
accounts = response.json() | ||
accounts_with_name = [] | ||
accessible_accounts = response.json() | ||
all_accounts: list[dict[str, str]] = [] | ||
|
||
for account in accounts["resourceNames"]: | ||
def dfs(account_id, accounts=None, parent_id=None) -> list[dict]: | ||
if accounts is None: | ||
accounts = [] | ||
response = requests.request( | ||
"POST", | ||
f"https://googleads.googleapis.com/v18/customers/{account.split('/')[1]}/googleAds:searchStream", | ||
f"https://googleads.googleapis.com/v18/customers/{account_id}/googleAds:searchStream", | ||
json={ | ||
"query": "SELECT customer_client.descriptive_name, customer_client.client_customer FROM customer_client WHERE customer_client.level <= 1" | ||
"query": "SELECT customer_client.descriptive_name, customer_client.client_customer, customer_client.level, customer_client.manager, customer_client.status FROM customer_client WHERE customer_client.level <= 5" | ||
}, | ||
headers={ | ||
"Content-Type": "application/json", | ||
"Authorization": f"Bearer {self.integration.sensitive_config['access_token']}", | ||
"developer-token": settings.GOOGLE_ADS_DEVELOPER_TOKEN, | ||
**({"login-customer-id": parent_id} if parent_id else {}), | ||
}, | ||
) | ||
|
||
if response.status_code != 200: | ||
continue | ||
return [] | ||
|
||
data = response.json() | ||
accounts_with_name.append( | ||
{ | ||
"id": account.split("/")[1], | ||
"name": data[0]["results"][0]["customerClient"].get("descriptiveName", "Google Ads account"), | ||
} | ||
) | ||
|
||
return accounts_with_name | ||
for nested_account in data[0]["results"]: | ||
if any( | ||
account["id"] == nested_account["customerClient"]["clientCustomer"].split("/")[1] | ||
and account["level"] > nested_account["customerClient"]["level"] | ||
for account in accounts | ||
): | ||
accounts = [ | ||
account | ||
for account in accounts | ||
if account["id"] != nested_account["customerClient"]["clientCustomer"].split("/")[1] | ||
] | ||
elif any( | ||
account["id"] == nested_account["customerClient"]["clientCustomer"].split("/")[1] | ||
and account["level"] < nested_account["customerClient"]["level"] | ||
for account in accounts | ||
): | ||
continue | ||
if nested_account["customerClient"].get("status") != "ENABLED": | ||
continue | ||
Comment on lines
+564
to
+565
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider logging disabled accounts for debugging purposes instead of silently skipping |
||
accounts.append( | ||
{ | ||
"parent_id": parent_id, | ||
"id": nested_account["customerClient"].get("clientCustomer").split("/")[1], | ||
"level": nested_account["customerClient"].get("level"), | ||
"name": nested_account["customerClient"].get("descriptiveName", "Google Ads account"), | ||
} | ||
) | ||
|
||
return accounts | ||
|
||
for account in accessible_accounts["resourceNames"]: | ||
all_accounts = dfs(account.split("/")[1], all_accounts, account.split("/")[1]) | ||
|
||
return all_accounts | ||
|
||
|
||
class GoogleCloudIntegration: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Add error handling for malformed requiresFieldValue that doesn't contain '/'