Add Google Tag Datalayer To Click

4 0 1

According to google tag, I need to add this form when someone clicks my products


 * Call this function when a user clicks on a product link. This function uses the event
 * callback datalayer variable to handle navigation after the ecommerce data has been sent
 * to Google Analytics.
 * @param {Object} productObj An object representing a product.
function(productObj) {
    'event': 'productClick',
    'ecommerce': {
      'click': {
        'actionField': {'list': 'Search Results'},      // Optional list property.
        'products': [{
          'name':,                      // Name or ID is required.
          'price': productObj.price,
          'brand': productObj.brand,
          'variant': productObj.variant,
          'position': productObj.position
     'eventCallback': function() {
       document.location = productObj.url


 But I don't know where shall I put it, where can I put this code so that it fires whenever someone clicks a product?