title: Google Tag Manager enhanced ecommerce data layer
body: <p>I'm implementing GTM and GA on our website and had a very basic question about passing the e-commerce data about product impressions and clicks which I'm not understanding from the official GTM documentation.</p>
  
  <p>As an example I would like to discuss the search result page. Our search result page will typically have 50-100 product listings on it. The SRP will load with the product impression pre-loaded in the dataLayer=[{...}] section in the  section with all the variables required by Google Tag Manager for impression calculation with the correct naming convention. As an example I would like to share the HTML pseudo code of the page</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  ....
  ....
      &lt;script&gt;
          dataLayer=[{
              'userID':'sdvkn3434mwgn4nk',
              'country':'USA',
              'language':'en-us',
              'ecommerce': {
                  currencyCode': 'USD',
                  'impressions': [
                      {
                       'name': 'Triblend Android T-Shirt',
                       'id': '12345',
                       'price': '15.25',
                       'brand': 'Google',
                       'category': 'Apparel',
                       'variant': 'Gray',
                       'list': 'Search Results',
                       'position': 1
                      },
                   {
                     'name': 'Donut Friday Scented T-Shirt',
                     'id': '67890',
                     'price': '33.75',
                     'brand': 'Google',
                     'category': 'Apparel',
                     'variant': 'Black',
                     'list': 'Search Results',
                     'position': 2
                   }]
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      ...
      ...
      &lt;a href="www.example.com/12345.html"&gt;Triblend Android T-Shirt&lt;/a&gt;
      &lt;a href="www.example.com/12345.html"&gt;Donut Friday Scented T-Shirt&lt;/a&gt;
      ....
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>In this dataLayer=[{}], we will also have data related to user language, user ID, country selected, etc</p>
  
  <p>I would like to understand how to calculate the click on a product. In the google documentation, <a href="https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks" rel="nofollow">https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks</a> it is mentioned to use the following code to track it.</p>
  
  <pre><code>&lt;script&gt;
  function(productObj) {
    dataLayer.push({
      'event': 'productClick',
      'ecommerce': {
        'click': {
          'actionField': {'list': 'Search Results'},      
          'products': [{
            'name': productObj.name,                      
            'id': productObj.id,
            'price': productObj.price,
            'brand': productObj.brand,
            'category': productObj.cat,
            'variant': productObj.variant
           }]
         }
       },
       'eventCallback': function() {
         document.location = productObj.url
       }
    });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Where should this function be declared? and where should this function be called? And how do we pass the values of the product ,i.e., name, id, price, etc to the function.</p>
  
  <p>I'm not a developer and will use help of a developer to get the information into the datalayer from the backend.</p>