Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we calculate the conversion time for each step using the windowFunnel function? #63732

Open
zhangmingchao opened this issue May 14, 2024 · 2 comments
Labels
cripshnot A user posted a screenshot or a photo of computer screen instead of a text question Question?

Comments

@zhangmingchao
Copy link

image
You can use the windowfunnel function to calculate the number of people in each step and the conversion rate, but what about the conversion time for those people?

@zhangmingchao zhangmingchao added the question Question? label May 14, 2024
@Algunenano Algunenano added the cripshnot A user posted a screenshot or a photo of computer screen instead of a text label May 14, 2024
@nikitamikhaylov
Copy link
Member

Please provide the table schema and the expected result of the query. It is super difficult to understand what is needed given only the information above.

@zhangmingchao
Copy link
Author

table structure

-- auto-generated definition
create table events_zc
(
_appkey String comment '分区字段,Appkey ',
_event_name String comment '分区字段,事件标识',
_user_id Int64 comment '用户唯一ID',
_event_time DateTime64(3) comment '事件时间,n 相当于数据中的_ts字段',
_db_time Int64 comment '入库时间'
)
engine = MergeTree PARTITION BY (toYYYYMM(_event_time))
ORDER BY (_event_name, _event_time, _user_id)
SETTINGS index_granularity = 8192;

data:

image

need:

My need is like a funnel, I need to calculate the transition time for each step, step 1 is _event_name=start step 2 is _event_name= visitor step 3 is _event_name= end, The window is 40 minutes. You can use the clickhouse windowFunnel function to calculate the number of converts per step, but you can't calculate the average conversion time per step

windowFunnel Sql

select
countIf(1, level >= 1) as step1,
countIf(1, level >= 2) as step2,
round(step2/step1,4) as step2_rate,
countIf(1, level >= 3) as step3,
round(step3/step2,4) as step3_rate
from (
select _user_id,
windowFunnel(2400)(toDateTime(_event_time), _event_name = 'start', _event_name = 'visitor',
_event_name = 'end') as level
from (
select *
from events_zc
order by _event_time, _user_id
) events_zc
group by _user_id
) data
image

What is the conversion time ?

Step 7 people, step 1 to step 6 people, so the six people (step 2 time - step 1 time)/6 is the average conversion time of the six people, excuse me, this demand, how should I achieve? From the data, you can see that the time of step 1 is 2024-01-01 10:00:00 and the time of step 2 is 2024-01-01 10:20:00, so the average conversion time is 1200s. How do I do that with ck?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cripshnot A user posted a screenshot or a photo of computer screen instead of a text question Question?
Projects
None yet
Development

No branches or pull requests

3 participants