|
5 | 5 | * See: https://www.gatsbyjs.org/docs/use-static-query/ |
6 | 6 | */ |
7 | 7 |
|
8 | | -import React from 'react'; |
| 8 | +import React, { useEffect } from 'react'; |
9 | 9 | import PropTypes from 'prop-types'; |
10 | 10 | import Helmet from 'react-helmet'; |
11 | 11 | import { useStaticQuery, graphql } from 'gatsby'; |
@@ -37,7 +37,34 @@ function SEO({ lang, |
37 | 37 | `, |
38 | 38 | ); |
39 | 39 |
|
40 | | - const isIndexed = !noindex ? 'index, follow' : 'noindex, nofollow' |
| 40 | + const isIndexed = !noindex ? 'index, follow' : 'noindex, nofollow'; |
| 41 | + |
| 42 | + const loadGTM = window.location.href.includes("tutorials"); |
| 43 | + |
| 44 | + useEffect(() => { |
| 45 | + if (loadGTM) { |
| 46 | + const script = document.createElement('script'); |
| 47 | + const noscript = document.createElement('noscript'); |
| 48 | + script.type = 'text/javascript'; |
| 49 | + script.innerHTML = ` |
| 50 | + (function(w,d,s,l,i){ |
| 51 | + w[l]=w[l]||[]; |
| 52 | + w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'}); |
| 53 | + var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; |
| 54 | + j.async=true; |
| 55 | + j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl; |
| 56 | + f.parentNode.insertBefore(j,f); |
| 57 | + })(window,document,'script','dataLayer','GTM-5F8HTVT'); |
| 58 | + `; |
| 59 | + noscript.innerHTML = ` |
| 60 | + <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5F8HTVT" |
| 61 | + height="0" width="0" style="display:none;visibility:hidden"> |
| 62 | + </iframe> |
| 63 | + ` |
| 64 | + document.head.appendChild(script); |
| 65 | + document.head.appendChild(noscript); |
| 66 | + } |
| 67 | + }, []); |
41 | 68 |
|
42 | 69 | return ( |
43 | 70 | <Helmet |
|
0 commit comments