• Resolved xamlkdslkjlkmkl

    (@alliquin)


    Hello,

    I want to setup this case.

    1. Visitor come from special utm_source (it’s define in URL parameters).
    2. For this visitor I want to keep the session based on first coming utm_source. If he come to another page of the website I want to show him only ads, which are define for this session.

    Please can you help me how can I do that? Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Spacetime

    (@spacetime)

    Hello,

    this is possible 🙂

    You need to configure two blocks.

    First explanation is for server-side code (when Dynamic blocks are set to Server-side = no caching) – only to show how to create cookies server-side:

    Block 1 (Set Cookie)
    Automatic insertion: disabled
    Shortcode: Enabled
    Page types: all enabled
    Url parameters: utm_source (White list)
    PHP processing: enabled

    Code:

    <?php
    setcookie ('utm_source_session', 'value', time() + (24 * 3600), COOKIEPATH);
    ?>

    Header code:

    [adinserter code="1"]
    
    [ADINSERTER HTTP]

    Block 2 (Session Ad)

    Set insertion and ad as needed
    Url parameters: utm_source, utm_source_session (White list)

    Explanation:

    Header code inserts raw HTTP header line (above [ADINSERTER HTTP] separator) from block 1 which sets cookie when utm_source url parameter is present.

    Shortcode [adinserter code="1"] ensures only block code is inserted (no wrapping div).

    https://adinserter.pro/documentation/plugin-settings#header-footer
    https://adinserter.pro/documentation/manual-insertion#shortcodes
    https://adinserter.pro/documentation/black-and-white-lists#url-parameters
    https://adinserter.pro/documentation/plugin-settings

    Block 2 inserts ad either when utm_source_session cookie is set or when utm_source url parameter is set (when no cookie created yet – first page visit via url parameter).

    And now universal approach with Javascript which works also with caching (Dynamic blocks set to client-side insert):

    Block 1 (Set Cookie)
    Automatic insertion: Footer
    Page types: all enabled
    Url parameters: utm_source (White list)

    Code:

    <script>
    function setCookie (name,value,days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days*24*60*60*1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "")  + expires + "; path=/";
    }
    setCookie ('utm_source_session', 'cookie_value', 1)
    </script>

    No Header code needed, Block 2 is the same.

    Thread Starter xamlkdslkjlkmkl

    (@alliquin)

    Hello, you are perfect! Thanks a lot. Just one question – if I want to setup session for 1 hour, how can I do that? Thanks.

    Plugin Author Spacetime

    (@spacetime)

    For server-side code instead of value for one day (24 * 3600) use 3600 (seconds).

    For universal Javascript code use

    <script>
    function setCookie (name,value,hours) {
        var expires = "";
        if (hours) {
            var date = new Date();
            date.setTime(date.getTime() + (hours*60*60*1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "")  + expires + "; path=/";
    }
    setCookie ('utm_source_session', 'cookie_value', 1)
    </script>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Session’ is closed to new replies.