xref: /aosp_15_r20/external/googleapis/google/analytics/admin/v1alpha/audience.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.analytics.admin.v1alpha;
18
19import "google/api/field_behavior.proto";
20import "google/api/resource.proto";
21import "google/protobuf/duration.proto";
22
23option go_package = "cloud.google.com/go/analytics/admin/apiv1alpha/adminpb;adminpb";
24option java_multiple_files = true;
25option java_outer_classname = "AudienceProto";
26option java_package = "com.google.analytics.admin.v1alpha";
27
28// Specifies how to evaluate users for joining an Audience.
29enum AudienceFilterScope {
30  // Scope is not specified.
31  AUDIENCE_FILTER_SCOPE_UNSPECIFIED = 0;
32
33  // User joins the Audience if the filter condition is met within one
34  // event.
35  AUDIENCE_FILTER_SCOPE_WITHIN_SAME_EVENT = 1;
36
37  // User joins the Audience if the filter condition is met within one
38  // session.
39  AUDIENCE_FILTER_SCOPE_WITHIN_SAME_SESSION = 2;
40
41  // User joins the Audience if the filter condition is met by any event
42  // across any session.
43  AUDIENCE_FILTER_SCOPE_ACROSS_ALL_SESSIONS = 3;
44}
45
46// A specific filter for a single dimension or metric.
47message AudienceDimensionOrMetricFilter {
48  // A filter for a string-type dimension that matches a particular pattern.
49  message StringFilter {
50    // The match type for the string filter.
51    enum MatchType {
52      // Unspecified
53      MATCH_TYPE_UNSPECIFIED = 0;
54
55      // Exact match of the string value.
56      EXACT = 1;
57
58      // Begins with the string value.
59      BEGINS_WITH = 2;
60
61      // Ends with the string value.
62      ENDS_WITH = 3;
63
64      // Contains the string value.
65      CONTAINS = 4;
66
67      // Full regular expression matches with the string value.
68      FULL_REGEXP = 5;
69    }
70
71    // Required. The match type for the string filter.
72    MatchType match_type = 1 [(google.api.field_behavior) = REQUIRED];
73
74    // Required. The string value to be matched against.
75    string value = 2 [(google.api.field_behavior) = REQUIRED];
76
77    // Optional. If true, the match is case-sensitive. If false, the match is
78    // case-insensitive.
79    bool case_sensitive = 3 [(google.api.field_behavior) = OPTIONAL];
80  }
81
82  // A filter for a string dimension that matches a particular list of options.
83  message InListFilter {
84    // Required. The list of possible string values to match against. Must be
85    // non-empty.
86    repeated string values = 1 [(google.api.field_behavior) = REQUIRED];
87
88    // Optional. If true, the match is case-sensitive. If false, the match is
89    // case-insensitive.
90    bool case_sensitive = 2 [(google.api.field_behavior) = OPTIONAL];
91  }
92
93  // To represent a number.
94  message NumericValue {
95    // One of a numeric value.
96    oneof one_value {
97      // Integer value.
98      int64 int64_value = 1;
99
100      // Double value.
101      double double_value = 2;
102    }
103  }
104
105  // A filter for numeric or date values on a dimension or metric.
106  message NumericFilter {
107    // The operation applied to a numeric filter.
108    enum Operation {
109      // Unspecified.
110      OPERATION_UNSPECIFIED = 0;
111
112      // Equal.
113      EQUAL = 1;
114
115      // Less than.
116      LESS_THAN = 2;
117
118      // Greater than.
119      GREATER_THAN = 4;
120    }
121
122    // Required. The operation applied to a numeric filter.
123    Operation operation = 1 [(google.api.field_behavior) = REQUIRED];
124
125    // Required. The numeric or date value to match against.
126    NumericValue value = 2 [(google.api.field_behavior) = REQUIRED];
127  }
128
129  // A filter for numeric or date values between certain values on a dimension
130  // or metric.
131  message BetweenFilter {
132    // Required. Begins with this number, inclusive.
133    NumericValue from_value = 1 [(google.api.field_behavior) = REQUIRED];
134
135    // Required. Ends with this number, inclusive.
136    NumericValue to_value = 2 [(google.api.field_behavior) = REQUIRED];
137  }
138
139  // One of the above filters.
140  oneof one_filter {
141    // A filter for a string-type dimension that matches a particular pattern.
142    StringFilter string_filter = 2;
143
144    // A filter for a string dimension that matches a particular list of
145    // options.
146    InListFilter in_list_filter = 3;
147
148    // A filter for numeric or date values on a dimension or metric.
149    NumericFilter numeric_filter = 4;
150
151    // A filter for numeric or date values between certain values on a dimension
152    // or metric.
153    BetweenFilter between_filter = 5;
154  }
155
156  // Required. Immutable. The dimension name or metric name to filter. If the
157  // field name refers to a custom dimension or metric, a scope prefix will be
158  // added to the front of the custom dimensions or metric name. For more on
159  // scope prefixes or custom dimensions/metrics, reference the [Google
160  // Analytics Data API documentation]
161  // (https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema#custom_dimensions).
162  string field_name = 1 [
163    (google.api.field_behavior) = REQUIRED,
164    (google.api.field_behavior) = IMMUTABLE
165  ];
166
167  // Optional. Indicates whether this filter needs dynamic evaluation or not. If
168  // set to true, users join the Audience if they ever met the condition (static
169  // evaluation). If unset or set to false, user evaluation for an Audience is
170  // dynamic; users are added to an Audience when they meet the conditions and
171  // then removed when they no longer meet them.
172  //
173  // This can only be set when Audience scope is ACROSS_ALL_SESSIONS.
174  bool at_any_point_in_time = 6 [(google.api.field_behavior) = OPTIONAL];
175
176  // Optional. If set, specifies the time window for which to evaluate data in
177  // number of days. If not set, then audience data is evaluated against
178  // lifetime data (For example, infinite time window).
179  //
180  // For example, if set to 1 day, only the current day's data is evaluated. The
181  // reference point is the current day when at_any_point_in_time is unset or
182  // false.
183  //
184  // It can only be set when Audience scope is ACROSS_ALL_SESSIONS and cannot be
185  // greater than 60 days.
186  int32 in_any_n_day_period = 7 [(google.api.field_behavior) = OPTIONAL];
187}
188
189// A filter that matches events of a single event name. If an event parameter
190// is specified, only the subset of events that match both the single event name
191// and the parameter filter expressions match this event filter.
192message AudienceEventFilter {
193  // Required. Immutable. The name of the event to match against.
194  string event_name = 1 [
195    (google.api.field_behavior) = REQUIRED,
196    (google.api.field_behavior) = IMMUTABLE
197  ];
198
199  // Optional. If specified, this filter matches events that match both the
200  // single event name and the parameter filter expressions. AudienceEventFilter
201  // inside the parameter filter expression cannot be set (For example, nested
202  // event filters are not supported). This should be a single and_group of
203  // dimension_or_metric_filter or not_expression; ANDs of ORs are not
204  // supported. Also, if it includes a filter for "eventCount", only that one
205  // will be considered; all the other filters will be ignored.
206  AudienceFilterExpression event_parameter_filter_expression = 2
207      [(google.api.field_behavior) = OPTIONAL];
208}
209
210// A logical expression of Audience dimension, metric, or event filters.
211message AudienceFilterExpression {
212  // The expression applied to a filter.
213  oneof expr {
214    // A list of expressions to be AND’ed together. It can only contain
215    // AudienceFilterExpressions with or_group. This must be set for the top
216    // level AudienceFilterExpression.
217    AudienceFilterExpressionList and_group = 1;
218
219    // A list of expressions to OR’ed together. It cannot contain
220    // AudienceFilterExpressions with and_group or or_group.
221    AudienceFilterExpressionList or_group = 2;
222
223    // A filter expression to be NOT'ed (For example, inverted, complemented).
224    // It can only include a dimension_or_metric_filter. This cannot be set on
225    // the top level AudienceFilterExpression.
226    AudienceFilterExpression not_expression = 3;
227
228    // A filter on a single dimension or metric. This cannot be set on the top
229    // level AudienceFilterExpression.
230    AudienceDimensionOrMetricFilter dimension_or_metric_filter = 4;
231
232    // Creates a filter that matches a specific event. This cannot be set on the
233    // top level AudienceFilterExpression.
234    AudienceEventFilter event_filter = 5;
235  }
236}
237
238// A list of Audience filter expressions.
239message AudienceFilterExpressionList {
240  // A list of Audience filter expressions.
241  repeated AudienceFilterExpression filter_expressions = 1;
242}
243
244// Defines a simple filter that a user must satisfy to be a member of the
245// Audience.
246message AudienceSimpleFilter {
247  // Required. Immutable. Specifies the scope for this filter.
248  AudienceFilterScope scope = 1 [
249    (google.api.field_behavior) = REQUIRED,
250    (google.api.field_behavior) = IMMUTABLE
251  ];
252
253  // Required. Immutable. A logical expression of Audience dimension, metric, or
254  // event filters.
255  AudienceFilterExpression filter_expression = 2 [
256    (google.api.field_behavior) = REQUIRED,
257    (google.api.field_behavior) = IMMUTABLE
258  ];
259}
260
261// Defines filters that must occur in a specific order for the user to be a
262// member of the Audience.
263message AudienceSequenceFilter {
264  // A condition that must occur in the specified step order for this user
265  // to match the sequence.
266  message AudienceSequenceStep {
267    // Required. Immutable. Specifies the scope for this step.
268    AudienceFilterScope scope = 1 [
269      (google.api.field_behavior) = REQUIRED,
270      (google.api.field_behavior) = IMMUTABLE
271    ];
272
273    // Optional. If true, the event satisfying this step must be the very next
274    // event after the event satisfying the last step. If unset or false, this
275    // step indirectly follows the prior step; for example, there may be
276    // events between the prior step and this step. It is ignored for the
277    // first step.
278    bool immediately_follows = 2 [(google.api.field_behavior) = OPTIONAL];
279
280    // Optional. When set, this step must be satisfied within the
281    // constraint_duration of the previous step (For example,  t[i] - t[i-1] <=
282    // constraint_duration). If not set, there is no duration requirement (the
283    // duration is effectively unlimited). It is ignored for the first step.
284    google.protobuf.Duration constraint_duration = 3
285        [(google.api.field_behavior) = OPTIONAL];
286
287    // Required. Immutable. A logical expression of Audience dimension, metric,
288    // or event filters in each step.
289    AudienceFilterExpression filter_expression = 4 [
290      (google.api.field_behavior) = REQUIRED,
291      (google.api.field_behavior) = IMMUTABLE
292    ];
293  }
294
295  // Required. Immutable. Specifies the scope for this filter.
296  AudienceFilterScope scope = 1 [
297    (google.api.field_behavior) = REQUIRED,
298    (google.api.field_behavior) = IMMUTABLE
299  ];
300
301  // Optional. Defines the time period in which the whole sequence must occur.
302  google.protobuf.Duration sequence_maximum_duration = 2
303      [(google.api.field_behavior) = OPTIONAL];
304
305  // Required. An ordered sequence of steps. A user must complete each step in
306  // order to join the sequence filter.
307  repeated AudienceSequenceStep sequence_steps = 3
308      [(google.api.field_behavior) = REQUIRED];
309}
310
311// A clause for defining either a simple or sequence filter. A filter can be
312// inclusive (For example, users satisfying the filter clause are included in
313// the Audience) or exclusive (For example, users satisfying the filter clause
314// are excluded from the Audience).
315message AudienceFilterClause {
316  // Specifies whether this is an include or exclude filter clause.
317  enum AudienceClauseType {
318    // Unspecified clause type.
319    AUDIENCE_CLAUSE_TYPE_UNSPECIFIED = 0;
320
321    // Users will be included in the Audience if the filter clause is met.
322    INCLUDE = 1;
323
324    // Users will be excluded from the Audience if the filter clause is met.
325    EXCLUDE = 2;
326  }
327
328  oneof filter {
329    // A simple filter that a user must satisfy to be a member of the Audience.
330    AudienceSimpleFilter simple_filter = 2;
331
332    // Filters that must occur in a specific order for the user to be a member
333    // of the Audience.
334    AudienceSequenceFilter sequence_filter = 3;
335  }
336
337  // Required. Specifies whether this is an include or exclude filter clause.
338  AudienceClauseType clause_type = 1 [(google.api.field_behavior) = REQUIRED];
339}
340
341// Specifies an event to log when a user joins the Audience.
342message AudienceEventTrigger {
343  // Determines when to log the event.
344  enum LogCondition {
345    // Log condition is not specified.
346    LOG_CONDITION_UNSPECIFIED = 0;
347
348    // The event should be logged only when a user is joined.
349    AUDIENCE_JOINED = 1;
350
351    // The event should be logged whenever the Audience condition is met, even
352    // if the user is already a member of the Audience.
353    AUDIENCE_MEMBERSHIP_RENEWED = 2;
354  }
355
356  // Required. The event name that will be logged.
357  string event_name = 1 [(google.api.field_behavior) = REQUIRED];
358
359  // Required. When to log the event.
360  LogCondition log_condition = 2 [(google.api.field_behavior) = REQUIRED];
361}
362
363// A resource message representing a GA4 Audience.
364message Audience {
365  option (google.api.resource) = {
366    type: "analyticsadmin.googleapis.com/Audience"
367    pattern: "properties/{property}/audiences/{audience}"
368  };
369
370  // Specifies how long an exclusion lasts for users that meet the exclusion
371  // filter.
372  enum AudienceExclusionDurationMode {
373    // Not specified.
374    AUDIENCE_EXCLUSION_DURATION_MODE_UNSPECIFIED = 0;
375
376    // Exclude users from the Audience during periods when they meet the
377    // filter clause.
378    EXCLUDE_TEMPORARILY = 1;
379
380    // Exclude users from the Audience if they've ever met the filter clause.
381    EXCLUDE_PERMANENTLY = 2;
382  }
383
384  // Output only. The resource name for this Audience resource.
385  // Format: properties/{propertyId}/audiences/{audienceId}
386  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
387
388  // Required. The display name of the Audience.
389  string display_name = 2 [(google.api.field_behavior) = REQUIRED];
390
391  // Required. The description of the Audience.
392  string description = 3 [(google.api.field_behavior) = REQUIRED];
393
394  // Required. Immutable. The duration a user should stay in an Audience. It
395  // cannot be set to more than 540 days.
396  int32 membership_duration_days = 4 [
397    (google.api.field_behavior) = REQUIRED,
398    (google.api.field_behavior) = IMMUTABLE
399  ];
400
401  // Output only. It is automatically set by GA to false if this is an NPA
402  // Audience and is excluded from ads personalization.
403  bool ads_personalization_enabled = 5
404      [(google.api.field_behavior) = OUTPUT_ONLY];
405
406  // Optional. Specifies an event to log when a user joins the Audience. If not
407  // set, no event is logged when a user joins the Audience.
408  AudienceEventTrigger event_trigger = 6
409      [(google.api.field_behavior) = OPTIONAL];
410
411  // Immutable. Specifies how long an exclusion lasts for users that meet the
412  // exclusion filter. It is applied to all EXCLUDE filter clauses and is
413  // ignored when there is no EXCLUDE filter clause in the Audience.
414  AudienceExclusionDurationMode exclusion_duration_mode = 7
415      [(google.api.field_behavior) = IMMUTABLE];
416
417  // Required. Immutable. Unordered list. Filter clauses that define the
418  // Audience. All clauses will be AND’ed together.
419  repeated AudienceFilterClause filter_clauses = 8 [
420    (google.api.field_behavior) = IMMUTABLE,
421    (google.api.field_behavior) = REQUIRED,
422    (google.api.field_behavior) = UNORDERED_LIST
423  ];
424}
425