How to select multiple custom Firebase event parameters in BigQuery?

前端 未结 3 1724
悲&欢浪女
悲&欢浪女 2020-12-31 08:21

I exported Firebase events to BigQuery and now I\'m trying to select two parameters from a certain event. Here is the query for selecting one parameter:

sele         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 08:32

    Another solution I find quite handy is to use User Defined Functions to analyze user properties and event parameters

    #Standard-SQL
    
    #UDF for event parameters
    CREATE TEMP FUNCTION paramValueByKey(k STRING, params ARRAY>>) AS (
      (SELECT x.value FROM UNNEST(params) x WHERE x.key=k)
    );
    
    #UDF for user properties
    CREATE TEMP FUNCTION propertyValueByKey(k STRING, properties ARRAY, set_timestamp_usec INT64, index INT64 > >>) AS (
      (SELECT x.value.value FROM UNNEST(properties) x WHERE x.key=k)
    );
    
    #Query the sample dataset, unnesting the events and turn 'api_version', 'round' and 'type_of_game' into columns 
    SELECT 
      user_dim.user_id,
      event.name,
      propertyValueByKey('api_version', user_dim.user_properties).string_value AS api_version,
     paramValueByKey('round', event.params).int_value as round,
     paramValueByKey('type_of_game', event.params).string_value as type_of_game
    FROM `firebase-analytics-sample-data.android_dataset.app_events_20160607`,
    UNNEST(event_dim) as event
    WHERE event.name = 'round_completed'
    LIMIT 10;
    

提交回复
热议问题