Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

Vue Cookies - Remarketing Cookies set to true though data set to false

We use the following to load cookies for mainly Google Analytics. We want remarketing or advertisement cookies off by default. We set data() remarketing to false but still remarketing is checked I the modal on firs load.

...
<button class="btn btn-primary" @click="apply" 
         :style="buttonStyle"><span v-html="projectInstance.cookiesMinibarButton"></span></button>
...
<div v-if="projectInstance.cookiesMinibarMarketingCookies" class="box-item">
  <strong>{{ projectInstance.cookiesMinibarMarketingTitle }}</strong>
  <div class="content">
    <span>
      <input type="checkbox" v-model="remarketing" class="smt-checkbox" id="cookies-remarketing">
      <label for="cookies-remarketing"></label>
    </span>
    <span v-html="projectInstance.cookiesMinibarMarketingDescription"></span>
  </div>
</div>
...
<div class="boxActions">
  <button class="btn btn-primary" @click="apply" 
    :style="{ color: projectInstance.cookiesMinibarModalTextColor, backgroundColor: projectInstance.cookiesMinibarModalButtonBackgroundColor }">let's go</button>
</div>
....
data() {
  return {
    cookiesFunctional: true,
    conversionTracking: true,
    remarketing: false,
  }
},
...
mounted() {
  if (window.isPublished) {
    this.conversionTracking = this.$cookies.get('cookies:analytical') == 'true' || this.$cookies.get('cookies:analytical') === null
    this.remarketing = this.$cookies.get('cookies:remarketing') == 'true' || this.$cookies.get('cookies:remarketing') === null
  }
},
...
// triggered by options modal let's go and by agree button
apply() {
if (window.isPublished) {
  this.$cookies.set('cookies:analytical', this.conversionTracking, '365d')
  this.$cookies.set('cookies:remarketing', this.remarketing, '365d')
  this.$cookies.set('cookies:accepted', true, '365d')
}
...
// agree to all but no longer in use
  agree() {
  this.conversionTracking = true
  this.remarketing = true
  this.apply()
},
...

Reading https://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php we do use == to check for a boolean value using true but we use === for second check for null.. perhaps there is an issue there. But that is PHP and not JS or Vue... but seems the same reading https://www.scaler.com/topics/javascript/difference-between-double-equals-and-triple-equals-in-javascript/

Any ideas what I am missing here getting true or remarketing checked though it should be false and data has it set to false?

In short, why is remarketing checked by default while it should not be?

0 likes
1 reply
rhand's avatar
rhand
OP
Best Answer
Level 6
mounted() {
  if (window.isPublished) {
    this.conversionTracking = this.$cookies.get('cookies:analytical') == 'true' || this.$cookies.get('cookies:analytical') === null
    this.remarketing = this.$cookies.get('cookies:remarketing') == 'true' || this.$cookies.get('cookies:remarketing') == false
  }
},

seems to work thought something like https://gist.github.com/jasperf/abf2d4780404ac214cfb6c50ea809725 also seems nice

Works. Also updated code some for accepting all cookies or accepting the ones checked.

acceptSelectedCookies() {
    if (window.isPublished) {
    if (this.conversionTracking) {
        this.$cookies.set('cookies:analytical', this.conversionTracking, '365d')
    }
    if (this.remarketing) {
        this.$cookies.set('cookies:remarketing', this.remarketing, '365d')
    }
    if (this.cookiesFunctional) {
        this.$cookies.set('cookies:accepted', true, '365d')
    }
    }

    EventBus.$emit('closed-cookies-modal')
    this.hideCookies()
},

acceptAllCookies() {
    if (window.isPublished) {
        this.$cookies.set('cookies:analytical', this.conversionTracking, '365d')
        this.$cookies.set('cookies:remarketing', this.remarketing, '365d')
        this.$cookies.set('cookies:accepted', true, '365d')
    }
    EventBus.$emit('closed-cookies-modal')
    this.hideCookies()
}

Please or to participate in this conversation.