-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Google Analytics v4: Added support for segments and filters #16920
Conversation
Thanks @krisjan-oldekamp for making this PR. This PR will be reviewed by a member of the community as part of Airbyte's Community Maintainer program. Someone will be assigned to review and help get your PR merged onto our main branch. Thanks for being patient! |
@sajarin I can pick this one for reviewing since it was initially assigned to me :) |
@itaseskii, awesome thanks for picking this up! |
@itaseskii Updated the docs and bumped the version in the Dockerfile |
@krisjan-oldekamp at first look this PR seems fine and inline with how the API works as explained in https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet I have one question related to filtering. Is there any semantic or capability based difference between a "filtersExpression" property and a "dimensionFilterClauses"? can you filter using a "filtersExpression" on regex values, range values, case sensitivity as in the GA4 query explorer https://ga-dev-tools.web.app/ga4/query-explorer/? |
@itaseskii The tool you're referring to is related to Google Analytics 4. This connector is related to the old version of GA, Universal Analytics Core Reporting API version 4, so it's a bit confusing. So the query explorer tool for Google Universal Analytics is using the exact same methods as used in this connector (the v3 style filter expressions and dynamic segment definitions). You can use RegEx in these filters (which you could also use for ranges), but Regex in filtersExpression is case insensitive. However the v3 style definitions are pretty much industry standard for years (almost every other tool that uses the GA Core Reporting API is using the v3 style declarations). |
@sajarin Can you please run the acceptance test suite? :) |
@sajarin / @itaseskii added a fix, because the connection test didn't pass, so good to go for the acceptance test. |
@sajarin could you take a look at this, please? |
/test connector=connectors/source-google-analytics-v4
Build PassedTest summary info:
|
…q#16920) * Google Analytics v4: Added support for segments and filters * Bumped version to 0.1.26 and updated docs * Fix connection test * Fix merge conflict (connector version)
@krisjan-oldekamp huge thanks for taking on this one! |
I run into errors when using Google Analytics (Universal Analytics) It seems the model is missing segments in the property: I am just starting to use airbyte, don't know how to test from my side. Could you verify it? |
I have just created a new connector with the line changed above, it works for me. Also, it is annoying that the deleting source is missing from the GUI. |
@DaiZack do you have any recommendations on how to filter the data based on the column ga:isConversionEvent? None of them worked. They pass through the testing on Airbyte, but the data returned comes unfiltered. |
@ViniciusARZ you might be confusing the Google Analytics Core Reporting API v4, with the Google Analytics 4 Data API. I believe Google Analytics Core Reporting API v4 does not have the ga:isConversionEvent dimension, it is only present in the GA4 Data API. |
@JonasBolin It actually does work. The extraction works perfectly and the isConversionEvent dimension comes with normal data, as expected. The only thing I'm not being able to achieve is filtering by it, since I wanted it to return only records with |
|
Do you have any recommendations on how to filter by this column? I also tried adding the segments dimension, and it still got the data unfiltered. |
What
Also see this issue: #6305
Since I needed these options for a client project pretty soon, I updated the connector with the options described below (although someone else already claimed the issue in April).
Added the "segments" request parameter to custom report options
So we can fetch segmented data from the Google Analytics API.
There are two ways to add a segment:
Since method 1 is way simpler and can achieve most use cases (and most analylist are familier with these segment definitions), I've chosen for option 1.
When using segments, the dimension
ga:segments
has to be added, because when adding more than 1 segment, data gets multiplied (e.g. for every segment configured). The ga:segments dimension will make sure you can differentiate on segment.Example custom report definition
Using a segment-ID (3) of an existing segment in the GA interface (tip: update documentation with these examples):
[{"name": "sessions_segment", "dimensions": ["ga:date", "ga:segment"], "metrics": ["ga:pageviews","ga:sessions","ga:users","ga:transactions"], "segments": ["gaid::-3"]}]
Using the (backwards compatible) segment syntax of the V3 api (see https://developers.google.com/analytics/devguides/reporting/core/v3/reference#segment)
[{"name": "sessions_segment", "dimensions": ["ga:date", "ga:segment"], "metrics": ["ga:pageviews","ga:sessions","ga:users","ga:transactions"], "segments": ["sessions::condition::ga:browser==Chrome"]}]
Added the filter option to custom report options
Again two options available, the more complicated v4 filter syntax, or the simplified (most known) v3 format: https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
Selected the v3 format.
Usage (tip: update documentation with these examples):
See filter expression list: https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
[{"name": "sessions_filter", "dimensions": ["ga:date", "ga:deviceCategory"], "metrics": ["ga:pageviews","ga:sessions","ga:users","ga:transactions"], "filter": "ga:deviceCategory==desktop}]
Testing
I tested my connector using a separate integration test catalog:
python main.py read --config secrets/service_config.json --catalog integration_tests/configured_catalog_segment_filters.json
Where I used these configuration values for the segments / filters -> it will only return the data for browser = Chrome (segment) and only for 2022-09-01 (put a filter on the date dimension)
"custom_reports": "[{\"name\": \"sessions_segment\", \"dimensions\": [\"ga:date\", \"ga:segment\"], \"metrics\": [\"ga:pageviews\",\"ga:sessions\",\"ga:users\",\"ga:transactions\",\"ga:itemQuantity\"], \"segments\": [\"sessions::condition::ga:browser==Chrome\"], \"filter\": \"ga:date==20220901\"}]"
Recommended reading order
x.java
y.python
🚨 User Impact 🚨
No breaking changes, only extra options in the custom report fields.
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesTests
Unit
Put your unit tests output here.
Integration
Put your integration tests output here.
Acceptance
Put your acceptance tests output here.