<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Angrej Kumar</title>
    <description>The latest articles on DEV Community by Angrej Kumar (@angrejkumar).</description>
    <link>https://dev.to/angrejkumar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1228332%2F99ef656b-3ea2-4dd1-b0a8-59067a0247ec.png</url>
      <title>DEV Community: Angrej Kumar</title>
      <link>https://dev.to/angrejkumar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/angrejkumar"/>
    <language>en</language>
    <item>
      <title>Google TagManager snippet is affecting total block time in pageinsights</title>
      <dc:creator>Angrej Kumar</dc:creator>
      <pubDate>Thu, 07 Dec 2023 13:51:32 +0000</pubDate>
      <link>https://dev.to/angrejkumar/google-tagmanager-snippet-is-affecting-total-block-time-in-pageinsights-4ig5</link>
      <guid>https://dev.to/angrejkumar/google-tagmanager-snippet-is-affecting-total-block-time-in-pageinsights-4ig5</guid>
      <description>&lt;p&gt;In my NextJS application I have added google tag manager embed code like this in a separate component and then I call this component in _app.tsx, but when I add this my &lt;a href="https://pagespeed.web.dev/"&gt;https://pagespeed.web.dev/&lt;/a&gt; Total Blocking Time increased. I think google tag manager is loading asynchronously, but not me for me I think. Not sure what wrong I'm doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client"

import { GTM_ID, pageview } from "@/lib/gtm"
import { usePathname, useSearchParams } from "next/navigation"
import Script from "next/script"
import { useEffect } from "react"

export default function Analytics() {
  const pathname = usePathname()
  const searchParams = useSearchParams()

  useEffect(() =&amp;gt; {
    if (pathname) {
      pageview(pathname)
    }
  }, [pathname, searchParams])

  if (process.env.NODE_ENV !== "production") {
    return null
  }

  return (
    &amp;lt;&amp;gt;
      &amp;lt;noscript&amp;gt;
        &amp;lt;iframe
          src={`https://www.googletagmanager.com/ns.html?id=${GTM_ID}`}
          height="0"
          width="0"
          style={{ display: "none", visibility: "hidden" }}
        /&amp;gt;
      &amp;lt;/noscript&amp;gt;
      &amp;lt;Script
        id="gtm-script"
        strategy="afterInteractive"
        dangerouslySetInnerHTML={{
          __html: `
    (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&amp;amp;l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer', '${GTM_ID}');
  `,
        }}
      /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can please some help? I'm using NextJS 13.3&lt;/p&gt;

</description>
      <category>tagamanger</category>
      <category>googleanalytics</category>
      <category>nextjs</category>
      <category>nextjs13</category>
    </item>
  </channel>
</rss>
