Answers.Body: <p>You could try something like </p>
  
  <pre><code>  {% set vidAlreadyPlayed = getSecureCookie('intro-animation') %}
          {% if not vidAlreadyPlayed %}
              {{ setSecureCookie('intro-animation', 'hey', now | date_modify("+60 seconds").timestamp ) }}
              &lt;h1&gt;No cookie set&lt;/h1&gt;
              &lt;!-- do your animation logic here --&gt;
          {% else %}
            &lt;!-- do something else --&gt;
            &lt;h1&gt;Cookie set already&lt;/h1&gt;
          {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T10:20:39.270Z
Answers.Text: No that didn't work unfortunately. But thanks for the suggestion
Answers.UserDisplayName: dave
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T10:26:09.893Z
Answers.Text: which bit didn't work? i'm using similar code on one of my sites, just not using secure cookie (but same plugin). Have you tried just outputting some text in each if/else bit to try and see whats happening?
Answers.UserDisplayName: alexr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T10:36:28.317Z
Answers.Text: I changed it to just text only and not a secure cookie as well to see if that was the issue, but it still just shows the same text each time
Answers.UserDisplayName: dave
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T10:45:56.683Z
Answers.Text: is it finding the cookie? e.g. is it defaulting to whats in the if or whats in the else?
Answers.UserDisplayName: alexr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T10:51:34.943Z
Answers.Text: It's showing whats in the if. i.e. I've just set it to say hello. So am seeing that only
Answers.UserDisplayName: dave
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T11:12:54.637Z
Answers.Text: sorry i'm being slow - realised you need to set a value for the cookie i think. e.g. `{{ setCookie('intro-animation', 'anyvalue', now | date_modify("+1 hour").timestamp ) }}`  - the last bit is an expiry so it'll last one hour there in that example
Answers.UserDisplayName: alexr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T11:20:09.537Z
Answers.Text: i've updated my answer, with a value and the cookie expiring after 60 seconds, which worked for me: first load, it says cookie not set. refresh shows cookie now set. leave a minute and refresh, it shows cookie not set again.
Answers.UserDisplayName: alexr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T11:24:27.200Z
Answers.Text: thanks alexr that's great. Thought it must be something simple. Just couldn't work it out from the docs. Much appreciated :)
Answers.UserDisplayName: dave
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T10:07:57.533Z
Answers.LastActivityDate: 2018-06-13T11:18:41.663Z
Answers.LastEditDate: 2018-06-13T11:18:41.663Z
Answers.UserDisplayName: alexr
Body: <p>I'm a Craft beginner, so forgive me if this is an easy question. </p>
  
  <p>I have an intro animation, that I'd only like to show on the first visit to the site, so that it doesn't load again when the user navigates back to the homepage after visiting other pages. Then I'd like it to expire when a user closes their browser.</p>
  
  <p>I'd like to use secure cookies via the <a href="https://github.com/nystudio107/cookies" rel="nofollow noreferrer">Cookies Plugin</a></p>
  
  <p>The id of the intro animation is <code>id="preloader"</code></p>
  
  <p>I've put <code>{{ setSecureCookie('intro-animation') }}</code> above the html tag and <code>{{ getSecureCookie('intro-animation') }}</code> with the preloader section.</p>
  
  <p>So how I do I set it up to only show the intro animation on first visit?</p>
  
Tags: <cookies>
Title: How to set cookie to only show intro animation once per session
ThreadText: # How to set cookie to only show intro animation once per session
  
  (Asked by: username_0 on 2018-06-13)
  
  I'm a Craft beginner, so forgive me if this is an easy question.
  
  I have an intro animation, that I'd only like to show on the first visit to the site, so that it doesn't load again when the user navigates back to the homepage after visiting other pages. Then I'd like it to expire when a user closes their browser.
  
  I'd like to use secure cookies via the [Cookies Plugin](https://github.com/nystudio107/cookies)
  
  The id of the intro animation is `id="preloader"`
  
  I've put `{{ setSecureCookie('intro-animation') }}` above the html tag and `{{ getSecureCookie('intro-animation') }}` with the preloader section.
  
  So how I do I set it up to only show the intro animation on first visit?
  
  **Tags:** cookies
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-13. Score: 1 | Accepted answer
  
  You could try something like
  
  ```
    {% set vidAlreadyPlayed = getSecureCookie('intro-animation') %}
          {% if not vidAlreadyPlayed %}
              {{ setSecureCookie('intro-animation', 'hey', now | date_modify("+60 seconds").timestamp ) }}
              <h1>No cookie set</h1>
              <!-- do your animation logic here -->
          {% else %}
            <!-- do something else -->
            <h1>Cookie set already</h1>
          {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: No that didn't work unfortunately. But thanks for the suggestion  
  > **username_1**: which bit didn't work? i'm using similar code on one of my sites, just not using secure cookie (but same plugin). Have you tried just outputting some text in each if/else bit to try and see whats happening?  
  > **username_0**: I changed it to just text only and not a secure cookie as well to see if that was the issue, but it still just shows the same text each time  
  > **username_1**: is it finding the cookie? e.g. is it defaulting to whats in the if or whats in the else?  
  > **username_0**: It's showing whats in the if. i.e. I've just set it to say hello. So am seeing that only  
  > **username_1**: sorry i'm being slow - realised you need to set a value for the cookie i think. e.g. `{{ setCookie('intro-animation', 'anyvalue', now | date_modify("+1 hour").timestamp ) }}`  - the last bit is an expiry so it'll last one hour there in that example  
  > **username_1**: i've updated my answer, with a value and the cookie expiring after 60 seconds, which worked for me: first load, it says cookie not set. refresh shows cookie now set. leave a minute and refresh, it shows cookie not set again.  
  > **username_0**: thanks username_1 that's great. Thought it must be something simple. Just couldn't work it out from the docs. Much appreciated :)  
  
  ---
  
  