<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>

CC BY-SA 4.0
2018-06-13T10:20:39.270Z
No that didn't work unfortunately. But thanks for the suggestion
dave
CC BY-SA 4.0
2018-06-13T10:26:09.893Z
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?
alexr
CC BY-SA 4.0
2018-06-13T10:36:28.317Z
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
dave
CC BY-SA 4.0
2018-06-13T10:45:56.683Z
is it finding the cookie? e.g. is it defaulting to whats in the if or whats in the else?
alexr
CC BY-SA 4.0
2018-06-13T10:51:34.943Z
It's showing whats in the if. i.e. I've just set it to say hello. So am seeing that only
dave
CC BY-SA 4.0
2018-06-13T11:12:54.637Z
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
alexr
CC BY-SA 4.0
2018-06-13T11:20:09.537Z
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.
alexr
CC BY-SA 4.0
2018-06-13T11:24:27.200Z
thanks alexr that's great. Thought it must be something simple. Just couldn't work it out from the docs. Much appreciated :)
dave
CC BY-SA 4.0
2018-06-13T10:07:57.533Z
2018-06-13T11:18:41.663Z
2018-06-13T11:18:41.663Z
alexr
<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>

<cookies>
How to set cookie to only show intro animation once per session
# 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 ) }}
            No cookie set
            
        {% else %}
          
          Cookie set already
        {% 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 alexr that's great. Thought it must be something simple. Just couldn't work it out from the docs. Much appreciated :)  

---

