Google Analytics (GA4) Admin Operators¶
Google Analytics (GA4) Admin operators allow you to lists all accounts to which the user has access. For more information about the Google Analytics 360 API check official documentation.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
List the Accounts¶
To list accounts from Analytics you can use the
GoogleAnalyticsAdminListAccountsOperator
.
list_accounts = GoogleAnalyticsAdminListAccountsOperator(
task_id="list_account",
gcp_conn_id=CONNECTION_ID,
show_deleted=True,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, page_size
, page_token
Create Property¶
Creates a property.
To create a property you can use the
GoogleAnalyticsAdminCreatePropertyOperator
.
create_property = GoogleAnalyticsAdminCreatePropertyOperator(
task_id="create_property",
analytics_property={
"parent": f"accounts/{get_google_analytics_account_id_task}",
"display_name": "Test display name",
"time_zone": "America/Los_Angeles",
},
gcp_conn_id=CONNECTION_ID,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, analytics_property
Delete Property¶
Deletes a property.
To delete a property you can use the
GoogleAnalyticsAdminDeletePropertyOperator
.
delete_property = GoogleAnalyticsAdminDeletePropertyOperator(
task_id="delete_property",
property_id=PROPERTY_ID,
gcp_conn_id=CONNECTION_ID,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, property_id
Create Data stream¶
Creates a data stream.
To create a data stream you can use the
GoogleAnalyticsAdminCreateDataStreamOperator
.
create_data_stream = GoogleAnalyticsAdminCreateDataStreamOperator(
task_id="create_data_stream",
property_id=PROPERTY_ID,
data_stream={
"display_name": "Test data stream",
"web_stream_data": {
"default_uri": "www.example.com",
},
"type_": google_analytics.DataStream.DataStreamType.WEB_DATA_STREAM,
},
gcp_conn_id=CONNECTION_ID,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, property_id
, data_stream
Delete Data stream¶
Deletes a data stream.
To delete a data stream you can use the
GoogleAnalyticsAdminDeleteDataStreamOperator
.
delete_data_stream = GoogleAnalyticsAdminDeleteDataStreamOperator(
task_id="delete_datastream",
property_id=PROPERTY_ID,
data_stream_id=DATA_STREAM_ID,
gcp_conn_id=CONNECTION_ID,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, property_id
, data_stream_id
List Google Ads Links¶
To list Google Ads links you can use the
GoogleAnalyticsAdminListGoogleAdsLinksOperator
.
list_google_ads_links = GoogleAnalyticsAdminListGoogleAdsLinksOperator(
task_id="list_google_ads_links",
property_id=get_google_ads_property_id_task,
gcp_conn_id=CONNECTION_ID,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, property_id
, page_size
, page_token
Get the Google Ads link¶
To list Google Ads links you can use the
GoogleAnalyticsAdminGetGoogleAdsLinkOperator
.
get_ad_link = GoogleAnalyticsAdminGetGoogleAdsLinkOperator(
task_id="get_ad_link",
property_id=get_google_ads_property_id_task,
google_ads_link_id=GA_ADS_LINK_ID,
gcp_conn_id=CONNECTION_ID,
)
You can use Jinja templating with
gcp_conn_id
, impersonation_chain
, google_ads_link_id
, property_id