window.getWpCookie = function(name) { match = document.cookie.match(new RegExp(name + '=([^;]+)')); if (match) return decodeURIComponent(match[1].replace(/\+/g, ' ')) ; }; window.dataLayer = window.dataLayer || []; var dlObjects = [{"pageName":"Never Too Old Charity Shop - Gems","pageType":"other","google_tag_params":{"ecomm_pagetype":"other"}}]; for (var i in dlObjects) { window.dataLayer.push(dlObjects[i]); } var wpCookies = ['wp_customerId','wp_customerGroup']; wpCookies.map(function(cookieName) { var cookieValue = window.getWpCookie(cookieName); if (cookieValue) { var dlObject = {}; dlObject[cookieName.replace('wp_', '')] = cookieValue; window.dataLayer.push(dlObject); } });