How do I execute this code waiting for page load and clicking the link

The following “view” code is attached to my home_controller’s
optimost_index.html.erb method. The sole purpose of this code is to
deposit a cookie on the user’s browser:

<%= javascript_include_tag
https://optixxx.com/es/352/c/26/u/Optimost.js” %>

<%= link_to “click here to proceed”, home_path %>

If I execute it without waiting for the page load and then redirecting
the control, then the cookies don’t get written. So I introduced the
last line shown above, i.e.,

<%= link_to “click here to proceed”, home_path %>

This way, the cookies are written by this third party code which I then
read in my own code. But I don’t want the users to have to click on
“click here to proceed” link. Instead, I want the Javascript code to
write the cookie and redirect to the home_path invisibly and
unobstrusively like so:

<%= redirect_to_real_home %>

Except, the cookies do not get written if I take out the link shown
above and insert the redirect_to call shown.

Is there a clean way of accomplishing this?

Thanks.

Bharat