title: Google Tag Manager: cart persistency
body: <p>in Google Tag Manager and Google Analytics, I am trying to track cart addition so that I can then compare them with effective purchases and see which product I am losing most of my business for.</p>
  
  <p>Till here, I am fine. I set up the following data layer with a product array.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    for (var i=0; i &lt; myvariable.length; i++) {
          window.dataLayer = window.dataLayer || [];
          window.dataLayer.push ({
              'event': 'AddtoCart',
              'ecommerce': {
                  'currencyCode': myvariable[i]['currency'],
                  'add': {
                      'products': [{
                          'name': myvariable[i]['name'],
                          'id': myvariable[i]['id'],
                          'category': myvariable[i]['category'],
                          'price': myvariable[i]['price'],
                          'variant': myvariable['variant'],
                          'dimension1': myvariable[i]['mydimension'],
                          'quantity': 1,
                        }]
                  }
              }
          });
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Now, I need to persist data layer throughout the different ecommerce steps in order not to duplicate the values every time user goes ahead or even jump backwards. And here is the problem, based on the structure of the ecommerce I work with:</p>
  
  <ul>
  <li>Page 1: product list</li>
  <li>Page 2 (optional, depending on the settings): product upgrades</li>
  <li>Page 3: Guest details</li>
  <li>Page 4: Confirmation</li>
  </ul>
  
  <p>In page 1 when a user selects a product he jumps directly to page 2 (if present) or 3. If he wants to select another product he has to go back and select again. All products are stored in the cart, which is generated as soon as the user adds a product, regardless of page the user is.</p>
  
  <p>What I would like to have is to track all product listed in the cart before he either closes the page/jumps out of the purchase process or confirms the purchase. It doesn´t really matter what he adds, removes, re-adds during the purchase process. Basically the last cart status (with all products listed) is what I want to be sent to Google Analytics as an event.</p>
  
  <p>I understand this is something I can achive with cookies, but not sure how exactly I should set it up, store all data in it and then trigger it to GA. I would really appreciate a few hints in this matter.</p>
  
  <p>Thanks in advance for your help.</p>