Calculated fields using GA4 event parameters

I’m trying to setup a calculated field in Looker Studio using GA4 event parameter I’ve set up for consent activity. It’s called action_type and the values are displayed, accept_all, and reject_all. What I’m trying to do is to set up a calculated field to measure accept_rate and reject_rate. First I set a field for consent_display, consent_accept, and consent_reject. However, when this metric is setup in metrics → add calculated field by taking the consent_accept / consent_displayed I get back 0%. Is there a way to fix this?

Well Here’s the quick and short fix :backhand_index_pointing_down:

First of all Create metrics:

Consent Displayed: COUNT(CASE WHEN action_type = "displayed" THEN 1 END)
Consent Accepted: COUNT(CASE WHEN action_type = "accept_all" THEN 1 END)
Consent Rejected: COUNT(CASE WHEN action_type = "reject_all" THEN 1 END)

After that you need to Create rates:

Accept Rate: SAFE_DIVIDE(Consent Accepted, Consent Displayed)
Reject Rate: SAFE_DIVIDE(Consent Rejected, Consent Displayed)

Finally, Set field type to Percent → now it will calculate correctly.

Thanks. I created the metrics consent displayed, accepted, and rejected and then moved onto accept rate using the safe_divide formula. However, Looker Studio did not support the operator safe_divide. I then tried by just taking the consent accepted / consent displayed but got 0%. Please advise.

1 Like