'How to install LinkedIn Insight Tag with NextJs
To install the Tag, linkedIn suggest to add this snippet in the code.
They suggest: "Paste the Insight Tag code below in your website’s global footer, right above the closing HTML tag."
<script type="text/javascript">
_linkedin_partner_id = "93XXXX";
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
window._linkedin_data_partner_ids.push(_linkedin_partner_id);
</script><script type="text/javascript">
(function(l) {
if (!l){window.lintrk = function(a,b){window.lintrk.q.push([a,b])};
window.lintrk.q=[]}
var s = document.getElementsByTagName("script")[0];
var b = document.createElement("script");
b.type = "text/javascript";b.async = true;
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
s.parentNode.insertBefore(b, s);})(window.lintrk);
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=933188&fmt=gif" />
</noscript>
Where should I paste this code with nextJs? in _document.tsx?
Solution 1:[1]
I at first also thought _document.tsx is where this tag should go, because that is where I saw the <body>.
But, it turns out _document.tsx is good for static things, and not necessarily for <Script> tags. Thankfully with next/script there's a bit more freedom. With the <Script> tag, Next will use the strategy prop to place the script in the correct place. strategy="lazyOnload" is probably the best for most social tags. And _app.tsx is the best place to put them.
I hope this helps, and good luck!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kimberlee Johnson |
