Communicate between HTML body start script and Page Code

I am working on an integration with Rewardful to add an affiliate system to my website. The referral ID is stored in the window object. I know it is not possible to access the window object in page code, but I need to know the referral ID in the page code so that I can append it to my Stripe payment URL so that the affiliate ID is accounted for in Stripe payment.

I was able to add custom HTML code to the body start and I can successfully access the referral ID and log it out. However, I need this in page code so that I can append it to my Stripe URL.

Can someone help me figure out how I can accomplish this. It seems like I need to either:

  1. Find a way to pass the referral ID from the HTML code in the body to the page code.
  2. Find a way to assign the Stripe URL to the button from the HTML body code.
  3. Find a way to access the window in the page code so that I can access the referral ID.

For reference, the following script code successfully logs out the correct referralId when placed in Settings > Custom Code > Body - Start.

Any help would be GREATLY appreciated!

https://www.wix.com/velo/reference/$w/htmlcomponent/postmessage

Thanks for sharing. Unfortunately I tried this previously and it did not work. I added an HTML element to my page and for some reason the Rewardful info in the window does not work as expected in that HTML element on my page code, but it works in the Body - Start script. Here are the two scenarios I’m seeing and only the first one works.

  1. Went to Settings > Custom Code > Body - Start and added a script that successfully access the referralId from the window object.

  2. Added HTML element on the page and when I try to access the referralId from the window in the same way as #1, it does not work.

In both cases I am just running this line of code to get the referallID

var referalId = window.Rewardful && window.Rewardful.referral || (‘checkout_’+(new Date).getTime());

However, in the first case the referral ID is correct and in the second case, the referralID defaults to the fallback ‘checkout_…’.

I’m not sure why the referralID is defined in the window object in scenario 1 (Body - Start script) but not in the second scenario (HTML element on the page)