How to create a Cookie?

Hello everyone,

I would like to set a Cookie after a user clicks on a button or a specific link. In plain JavaScript, it would be something like this:

document.cookie = “key=value”;

In the Corvid API, the closest thing I found was wix-storage, but this does not seem to set cookies. I also tried to embed the JavaScript code within an HTML-Code-Block, but this does not set a cookie for my actual site.

I would appreciate it very much if anyone could give me a hint how to set a simple cookie with Corvid!

Thanks,

Alexander

Hello David,

thank you for your reply. Let me give you more details regarding my problem.

I would like to set a cookie to disable Google Analytics. The name of the cookie should look something like this:

ga-disable-UA-XXXXX-Y

With wix-storage, I cannot achieve the desired behavior because it does not set a cookie with a given name.

Do you (or anyone else) know of a different way to set the ga-disable (or OptOut) cookie?

Thanks!

I’m not sure, but I guess you can add a snippet to the Analytics&Tracking on your dashboard to set a cookie onMessage(). https://www.w3schools.com/js/js_cookies.asp
Then on your site page add an html component and put there the postMessage that will trigger the cookie setting.

Hello J.D.,

thank you for your reply!

I added the required code to the header as described by you. Now, there is a header function called gaOptout().

I then added an HTML block with the following code:
Deactivate Google Analytics

However, when clicking this button, I get the following error in the Chrome developer console: “Uncaught ReferenceError: gaOptout is not defined”

Further, I am unable to call this function on a Wix page using Corvid.

Do you have any hints or ideas how to call the JavaScript function defined in the header?

I don’t know. I’ve never done it. What I said earlier was off the top of my head. I don’t know if it works and how exactly to deactivate Google Analytics.

Hi, I think I managed to create a GDPR-compliant Opt-In in Wix. I first tried with postMessage, but I didn’t get this to work. The Idea of the solution that works is to use local Wix storage (which saves a text file in your browser in the format key-value pair) and on html site code to block the Google Analytics until you read this “cookie” out of local storage. Once you find the “allowgoogleanalyticscookie”, then Google Analytics will start.

I will either create a youtube-video of this solution or post some advice here, maybe in a few days… :slight_smile: