title: Google Tag Manager: get value as variable after specific text
body: <p>I am trying to capture the value of the "sku" as a variable in GTM. This value will change on every product page.</p>
  
  <p>The code on page looks like this:</p>
  
  <pre><code>&lt;script type="application/ld+json"&gt;
  {
    "@context": "http://schema.org",
    "@type": "Product",
    "sku": "305FS-UJNA5",
    "offers": [{
          "@type": "Offer",
          "price": "99.00",
          "availability": "InStock",
          "priceCurrency": "USD"
          }]
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>The variable expected to be captured: 305FS-UJNA5 (without double quotes).</p>
  
  <p>Is there a way to accomplish this by using a custom javascript variable type that will search for <code>"sku": "</code> on the page and return the value till the next double quote?</p>
  
  <p>Or, what what would be the best way to accomplish this?</p>
  
  <p>I've tried the search but returns undefined in GTM...</p>
  
  <pre><code>function () {
  var content = document.body.innerText;
  var query=""sku": "";
  if (content.search(query) &gt; -1 ) {
      return true;
  } else {
      return false;
      }
  }
  </code></pre>