Class: Omnitrack::Adapters::GoogleAds
- Defined in:
- lib/omnitrack/adapters/google_ads.rb
Overview
Google Ads Conversion Tracking via the Google Ads API (REST).
Required config keys:
customer_id — Google Ads customer ID (without dashes), e.g. "1234567890"
developer_token — developer token from Google Ads API Center
access_token — OAuth2 access token (refresh externally or via oauth2 gem)
Optional config keys:
conversion_action_id — default conversion action ID
login_customer_id — MCC (manager account) customer ID, if applicable
api_version — default "v15"
Example config:
google_ads: {
enabled: true,
customer_id: ENV["GOOGLE_ADS_CUSTOMER_ID"],
developer_token: ENV["GOOGLE_ADS_DEVELOPER_TOKEN"],
access_token: ENV["GOOGLE_ADS_ACCESS_TOKEN"],
conversion_action_id: ENV["GOOGLE_ADS_CONVERSION_ACTION_ID"]
}
Constant Summary collapse
- API_VERSION =
"v15"- API_BASE =
"https://googleads.googleapis.com"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#identify_user(user_data = {}) ⇒ Object
Google Ads does not have a standalone identify endpoint; enhanced conversions use hashed PII attached to the conversion upload.
-
#track_conversion(data = {}) ⇒ Object
Track a conversion (alias with sensible defaults for purchase events).
-
#track_event(event_name, payload = {}) ⇒ Object
Track a named event.
Methods inherited from Base
#enabled?, inherited, #initialize, #name
Constructor Details
This class inherits a constructor from Omnitrack::Adapters::Base
Instance Method Details
#identify_user(user_data = {}) ⇒ Object
Google Ads does not have a standalone identify endpoint; enhanced conversions use hashed PII attached to the conversion upload. This method stores user data on the context for later use.
77 78 79 80 81 82 83 84 85 |
# File 'lib/omnitrack/adapters/google_ads.rb', line 77 def identify_user(user_data = {}) ctx = Omnitrack::Context.current ctx&.merge!(omnitrack_user: normalize_user(user_data)) Omnitrack::Result.success( adapter: name, metadata: { note: "User data stored in context for enhanced conversions" } ) end |
#track_conversion(data = {}) ⇒ Object
Track a conversion (alias with sensible defaults for purchase events)
70 71 72 |
# File 'lib/omnitrack/adapters/google_ads.rb', line 70 def track_conversion(data = {}) track_event("conversion", data) end |
#track_event(event_name, payload = {}) ⇒ Object
Track a named event. Maps to a Google Ads click conversion upload.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/omnitrack/adapters/google_ads.rb', line 47 def track_event(event_name, payload = {}) safe_execute(event_name) do gclid = extract_gclid(payload) action_id = payload[:conversion_action_id] || config[:conversion_action_id] body = build_conversion_body( gclid: gclid, conversion_action: action_resource(action_id), conversion_time: payload[:conversion_time] || iso_now, conversion_value: payload[:conversion_value], currency_code: payload[:currency_code] || "USD", order_id: payload[:order_id] ) response = http_post(upload_url, body: body, headers: auth_headers) Omnitrack::Result.success( adapter: name, data: parse_response(response) ) end end |