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:

List the Accounts

To list accounts from Analytics you can use the GoogleAnalyticsAdminListAccountsOperator.

tests/system/providers/google/marketing_platform/example_analytics_admin.py[source]

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.

tests/system/providers/google/marketing_platform/example_analytics_admin.py[source]

create_property = GoogleAnalyticsAdminCreatePropertyOperator(
    task_id="create_property",
    analytics_property={
        "parent": f"accounts/{ACCOUNT_ID}",
        "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.

tests/system/providers/google/marketing_platform/example_analytics_admin.py[source]

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.

tests/system/providers/google/marketing_platform/example_analytics_admin.py[source]

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.

tests/system/providers/google/marketing_platform/example_analytics_admin.py[source]

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

Was this entry helpful?