Skip to content

chore: use google ads SDK in GAEC destination - #4177

Merged
ItsSudip merged 10 commits into
developfrom
chore.use_google_sdk_gaec
Apr 7, 2025
Merged

ItsSudip merged 10 commits into
developfrom
chore.use_google_sdk_gaec

Conversation

@ItsSudip

@ItsSudip ItsSudip commented Mar 18, 2025 •

Copy link
Copy Markdown
Member

This pull request focuses on refactoring the Google AdWords Enhanced Conversions destination to use the Google Ads SDK and improve error handling. The most important changes include removing the BASE_ENDPOINT and API_VERSION constants, updating the network handler to use the Google Ads SDK, and modifying the test cases accordingly.

Refactoring to use Google Ads SDK and improve error handling:

Test case updates:

What are the changes introduced in this PR?

We are using googleAds SDK in google ads enhanced conversion destination.

What is the related Linear task?

Resolves INT-3400

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

@codecov

codecov Bot commented Mar 18, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.03%. Comparing base (322ddbc) to head (199f39a).
Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
...gle_adwords_enhanced_conversions/networkHandler.js 92.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4177      +/-   ##
===========================================
- Coverage    91.05%   91.03%   -0.02%     
===========================================
  Files          627      626       -1     
  Lines        33049    32915     -134     
  Branches      7818     7792      -26     
===========================================
- Hits         30092    29964     -128     
- Misses        2710     2734      +24     
+ Partials       247      217      -30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ItsSudip
ItsSudip marked this pull request as ready for review March 19, 2025 07:03
@ItsSudip
ItsSudip requested review from a team and sivashanmukh as code owners March 19, 2025 07:03
@ItsSudip
ItsSudip requested review from a team, sandeepdsvs and vinayteki95 March 19, 2025 07:03
@ItsSudip ItsSudip changed the title chore: use google ads sdk chore: use google ads SDK in GAEC destination Mar 19, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@ItsSudip
ItsSudip requested a review from koladilip March 19, 2025 11:17
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@coderabbitai

coderabbitai Bot commented Mar 20, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Conversion request payloads now include enhanced authentication parameters such as accessToken, developerToken, and loginCustomerId.
    • API error responses deliver structured JSON messages for improved clarity.
  • Refactor

    • Network request handling and conversion action retrieval have been streamlined.
    • Configuration settings and endpoint construction have been simplified for more consistent integration.
    • Endpoint URLs have been adjusted to use relative paths instead of full URLs.

Walkthrough

This update removes hardcoded API version and endpoint constants from multiple modules and tests. The network handler functions have been refactored to leverage the Google Ads SDK directly for obtaining conversion action IDs, with enhanced error handling. In addition, test integrations now omit the previously constructed endpoints in favor of empty strings while incorporating new authentication parameters such as developerToken, accessToken, and loginCustomerId.

Changes

File(s) Change Summary
src/v0/destinations/google_adwords_enhanced_conversions/config.js Removed constants API_VERSION and BASE_ENDPOINT and their exports.
src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js Refactored getConversionActionId to accept a googleAds parameter; simplified ProxyRequest (now gaecProxyRequest) by removing extra destructuring; replaced SQL queries with calls to googleAds.getConversionActionId; enhanced error handling via custom error classes.
src/v0/destinations/google_adwords_enhanced_conversions/transform.js Removed usage of BASE_ENDPOINT and updated the request parameters to include accessToken, loginCustomerId, and developerToken.
test/integrations/destinations/google_adwords_enhanced_conversions/{business.ts, oauth.ts, network.ts, processor/data.ts, router/data.ts} Removed the API_VERSION constant; changed endpoints to empty strings; added new parameters (accessToken, developerToken, loginCustomerId); updated payload structures and header formatting.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant PR as ProxyRequest Handler
    participant GA as GoogleAds SDK
    C->>PR: Send request with event and params
    PR->>GA: Call getConversionActionId(event)
    GA-->>PR: Return conversion action ID or error
    PR->>GA: Call addConversionAdjustment with conversion ID and params
    GA-->>PR: Return success/failure response
    PR-->>C: Return structured response
Loading

Possibly related PRs

  • chore: clean up old zoho logic after releasing vdmv2 #4189: The changes in the main PR are related to the removal of constants that affect API endpoint construction, similar to the removal of constants in the retrieved PR that also impacts endpoint logic for the Zoho API.
  • chore: sources v2 spec cleanup #4192: The changes in the main PR, which involve the removal of the API_VERSION and BASE_ENDPOINT constants, are related to the modifications in the retrieved PR that also involve the removal of the API_VERSION constant and adjustments to how endpoints are constructed, indicating a direct connection at the code level.

Suggested reviewers

  • sivashanmukh
  • krishna2020
  • yashasvibajpai
  • maheshkutty
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

koladilip
koladilip previously approved these changes Mar 20, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (1)

5-6: Remove commented-out code.

There are commented-out imports (NetworkInstrumentationError and SqlString) that should be removed if they're no longer needed to maintain code cleanliness.

- const {
  NetworkError,
-  // NetworkInstrumentationError,
  GoogleAdsSDK,
  InstrumentationError,
  isDefinedAndNotNullAndNotEmpty,
} = require('@rudderstack/integrations-lib');
- // const SqlString = require('sqlstring');

Also applies to: 10-10

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46af874d7002ea4cce20e61594a91bf769f37bbc and c140015.

📒 Files selected for processing (1)
  • src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (8)

3-9: Good update to import Google Ads SDK and required error handling utilities.

The imports now correctly include the necessary components from the @rudderstack/integrations-lib package, aligning with the PR objective to use the Google Ads SDK in the GAEC destination.


31-42: Good refactoring to use Google Ads SDK for conversion action ID retrieval.

The function signature has been appropriately updated to accept a googleAds parameter instead of the previously needed method, headers, and metadata. The implementation now properly leverages the SDK's getConversionActionId method and includes good error handling for the case when no conversion action is found.


43-53: Proper error handling for client errors.

This client-error handling block correctly uses the NetworkError class with appropriate error message formatting and propagates status code and error type information.


55-67: Good application error handling.

The application-error handling is well implemented, correctly formatting the error message and including all necessary error details for proper debugging and client communication.


77-89: Good implementation of Google Ads SDK initialization.

The ProxyRequest function has been simplified and now properly initializes the GoogleAds SDK with all required authentication parameters.


91-95: Clean implementation of conversion adjustment submission.

The code properly sets the conversion action ID in the request body and directly leverages the SDK's addConversionAdjustMent method.


98-102: Well-structured response processing function.

The gaecProcessAxiosResponse function correctly transforms the SDK response structure to match what the existing responseHandler expects, maintaining compatibility with the rest of the system.


148-148: Good implementation of the custom response processor.

The class is correctly updated to use the new gaecProcessAxiosResponse function, addressing the comment from the previous review about overriding the processAxiosResponse function.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

utsabc
utsabc previously approved these changes Mar 26, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@ItsSudip
ItsSudip dismissed stale reviews from utsabc and manish339k via 199f39a April 5, 2025 02:04
@ItsSudip
ItsSudip force-pushed the chore.use_google_sdk_gaec branch from e86e1e6 to 199f39a Compare April 5, 2025 02:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/v0/destinations/google_adwords_enhanced_conversions/transform.js (1)

52-64: Consider avoiding token duplication.

The developer token is fetched twice - once for headers and once for params. Consider extracting this to a variable to avoid duplication.

  const accessToken = getAccessToken(metadata, 'access_token');
+ const developerToken = getValueFromMessage(metadata, 'secret.developer_token');
  deliveryRequest.headers = {
    Authorization: `Bearer ${accessToken}`,
    'Content-Type': JSON_MIME_TYPE,
-   'developer-token': getValueFromMessage(metadata, 'secret.developer_token'),
+   'developer-token': developerToken,
  };
  const filteredLoginCustomerId = removeHyphens(loginCustomerId);
  deliveryRequest.params = {
    event,
    customerId: filteredCustomerId,
    accessToken,
    loginCustomerId: filteredLoginCustomerId,
-   developerToken: getValueFromMessage(metadata, 'secret.developer_token'),
+   developerToken,
  };
src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (2)

3-10: Updated imports for Google Ads SDK integration.

The imports have been updated to include the Google Ads SDK and necessary error handling utilities. Consider removing the commented-out imports for cleaner code.

const {
  NetworkError,
- // NetworkInstrumentationError,
  GoogleAdsSDK,
  InstrumentationError,
  isDefinedAndNotNullAndNotEmpty,
} = require('@rudderstack/integrations-lib');
-// const SqlString = require('sqlstring');
const { prepareProxyRequest } = require('../../../adapters/network');

31-74: Comprehensive refactoring of getConversionActionId.

The function has been refactored to use the Google Ads SDK directly instead of constructing SQL queries, with enhanced error handling for various response types. The error message for non-existent conversion actions is particularly helpful.

However, the error message formatting is inconsistent - some contain extra quotes that could cause confusion when reading logs.

  if (resp.type === 'client-error') {
    throw new NetworkError(
-     `"${resp.message} during Google_adwords_enhanced_conversions response transformation[client-error]"`,
+     `${resp.message} during Google_adwords_enhanced_conversions response transformation[client-error]`,
      resp.statusCode,
      {
        [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(resp.statusCode),
      },
      resp,
      getAuthErrCategory({ response: resp, status: resp.statusCode }),
    );
  }

  if (resp.type === 'application-error') {
    throw new NetworkError(
-     `"${JSON.stringify(resp.responseBody)} during Google_adwords_enhanced_conversions response transformation"`,
+     `${JSON.stringify(resp.responseBody)} during Google_adwords_enhanced_conversions response transformation`,
      resp.statusCode,
      {
        [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(resp.statusCode),
      },
      resp.responseBody,
      getAuthErrCategory({ response: resp.responseBody, status: resp.statusCode }),
    );
  }
  throw new NetworkError(
-   `"${JSON.stringify(resp)} during Google_adwords_enhanced_conversions response transformation"`,
+   `${JSON.stringify(resp)} during Google_adwords_enhanced_conversions response transformation`,
    500,
    {
      [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(500),
    },
    resp,
  );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c140015 and 199f39a.

📒 Files selected for processing (2)
  • src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (4 hunks)
  • src/v0/destinations/google_adwords_enhanced_conversions/transform.js (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).

**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).

  • src/v0/destinations/google_adwords_enhanced_conversions/transform.js
  • src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js
🧬 Code Definitions (1)
src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (2)
src/v0/destinations/google_adwords_enhanced_conversions/transform.js (5)
  • require (4-4)
  • require (5-5)
  • require (7-14)
  • require (16-16)
  • require (17-17)
src/v0/destinations/google_adwords_enhanced_conversions/config.js (2)
  • require (1-1)
  • CONVERSION_ACTION_ID_CACHE_TTL (7-9)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: ingestion-service-test
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (11)
src/v0/destinations/google_adwords_enhanced_conversions/transform.js (6)

16-16: Import change aligns with SDK migration.

The removal of BASE_ENDPOINT from the imports indicates the shift towards using the Google Ads SDK directly instead of hardcoded endpoints, which is a positive architectural change.


37-37: Good variable renaming from response to deliveryRequest.

This rename more accurately represents the purpose of the variable, improving code readability and addressing the previous review feedback.


50-50: Simplified payload assignment.

Direct assignment to deliveryRequest.body.JSON simplifies the code by removing endpoint construction logic.


57-57: Using filteredLoginCustomerId for both params and headers.

This is not a duplicate as correctly noted in previous comments - one usage is for the params object and the other is for headers.


75-75: Consistent use of filteredLoginCustomerId.

The code correctly uses the previously calculated filteredLoginCustomerId in the headers when subAccount is true.


78-78: Return updated variable name.

Updated return statement to use deliveryRequest instead of response, maintaining consistency with the variable renaming.

src/v0/destinations/google_adwords_enhanced_conversions/networkHandler.js (5)

18-18: Added utility for dynamic error type handling.

The import of getDynamicErrorType enhances error handling capabilities, providing more specific error categorization.


84-103: Renamed and improved proxy request implementation.

The function has been renamed to gaecProxyRequest for clarity and refactored to use the Google Ads SDK directly. The creation of the GoogleAds instance with the necessary authentication parameters is well structured.

Consider using template literals consistently:

- set(body.JSON, 'conversionAdjustments[0].conversionAction', `${conversionActionId}`);
+ set(body.JSON, 'conversionAdjustments[0].conversionAction', conversionActionId);

105-109: New function for Axios response processing.

The gaecProcessAxiosResponse function provides standardized processing of SDK responses, improving consistency across the codebase. The conditional spread of headers only when defined is a good practice.


110-148: Well-structured response handler with detailed error handling.

The gaecResponseHandler function includes comprehensive error handling for different response types, including the special case of partial failures with a 200 status code. The reference to the Google RPC code proto is helpful.


153-156: Updated networkHandler class with new function references.

The class now uses the renamed and improved functions, maintaining consistency with the overall refactoring approach.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Apr 5, 2025

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants