Thanks @Neophytos Demetriou
I am doing this for web app. I got solution for this, I did similar to your 3rd point.
I added the following code in my x.tcl which added count_num to "y.tcl url"
www.XXX/y?count_num=0
ad_returnredirect y?[ad_export_vars {count_num rel_type return_url}]
in y.tcl I added
ad_page_contract {
@author yourname
} {
count_num:optional
}
set count_num_p "f"
if {[exists_and_not_null count_num]} {
set count_num_p "t"
}
in y.adp
<if @count_num_p@ eq "t">
@count_num@
</if>