Skip to content

Commit 826a265

Browse files
authored
feat: add LinkedIn Insight and GTM scripts (#2098)
1 parent d26c18b commit 826a265

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

studio/.env.local.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ NEXT_PUBLIC_SENTRY_CLIENT_REPLAYS_SESSION_SAMPLE_RATE=
1717
# edge config
1818
NEXT_PUBLIC_SENTRY_EDGE_SAMPLE_RATE=
1919

20+
# analytics config
21+
NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=
22+
NEXT_PUBLIC_LINKEDIN_INSIGHT_ID=
23+
2024
# used by https://docs.sentry.io/platforms/javascript/guides/nextjs/
2125
# enable this during build to enable sentry support for custom images
2226
# when using debug, ensure the image was build with SENTRY_DEBUG="true"

studio/next.config.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ const lightweightCspHeader = `
5757
frame-src 'self' https://js.stripe.com https://hooks.stripe.com ${
5858
isPreview ? "https://vercel.live/ https://vercel.com" : ""
5959
};
60-
img-src 'self' ${
60+
img-src 'self'${
6161
isPreview
62-
? "https://vercel.live/ https://vercel.com *.pusher.com/ data: blob:"
62+
? " https://vercel.live/ https://vercel.com *.pusher.com/ data: blob:"
6363
: ""
64-
};
64+
} *.ads.linkedin.com;
6565
script-src 'report-sample' 'self' 'unsafe-inline' ${
6666
allowUnsafeEval ? "'unsafe-eval'" : ""
67-
} https://*.wundergraph.com https://js.stripe.com https://maps.googleapis.com https://plausible.io https://wundergraph.com https://static.reo.dev ${
68-
isPreview ? "https://vercel.live https://vercel.com" : ""
69-
};
67+
} https://*.wundergraph.com https://js.stripe.com https://maps.googleapis.com https://plausible.io https://wundergraph.com https://static.reo.dev${
68+
isPreview ? " https://vercel.live https://vercel.com" : ""
69+
} https://www.googletagmanager.com https://snap.licdn.com;
7070
manifest-src 'self';
7171
media-src 'self';
7272
worker-src 'self' ${isSentryFeatureReplayEnabled ? "blob:" : ""};

studio/src/pages/_document.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ const getCustomScripts = ():
1515

1616
export default function Document() {
1717
const scripts = getCustomScripts();
18+
const gtmId = process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID;
19+
const linkedInInsightId = process.env.NEXT_PUBLIC_LINKEDIN_INSIGHT_ID;
1820

1921
return (
2022
<Html className="antialiased [font-feature-settings:'ss01']" lang="en">
2123
<Head>
24+
{gtmId && (
25+
<script
26+
id="gtm"
27+
type="text/javascript"
28+
dangerouslySetInnerHTML={{
29+
__html:
30+
`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':` +
31+
`new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],` +
32+
`j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=` +
33+
`'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);` +
34+
`})(window,document,'script','dataLayer',${JSON.stringify(gtmId)});`,
35+
}}
36+
/>
37+
)}
38+
2239
<link
2340
rel="apple-touch-icon"
2441
sizes="57x57"
@@ -97,6 +114,17 @@ export default function Document() {
97114
<meta name="theme-color" content="#ffffff" />
98115
</Head>
99116
<body>
117+
{gtmId && (
118+
<noscript>
119+
<iframe
120+
src={`https://www.googletagmanager.com/ns.html?id=${gtmId}`}
121+
height="0"
122+
width="0"
123+
style={{ display: "none", visibility: "hidden" }}
124+
/>
125+
</noscript>
126+
)}
127+
100128
<Main />
101129
<NextScript />
102130

@@ -114,6 +142,44 @@ export default function Document() {
114142
/>
115143
),
116144
)}
145+
146+
{linkedInInsightId && (
147+
<>
148+
<script
149+
id="li-insight"
150+
type="text/javascript"
151+
dangerouslySetInnerHTML={{
152+
__html: `
153+
_linkedin_partner_id = ${JSON.stringify(linkedInInsightId)};
154+
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
155+
window._linkedin_data_partner_ids.push(_linkedin_partner_id);
156+
157+
(function(l) {
158+
if (!l){
159+
window.lintrk = function(a,b){window.lintrk.q.push([a,b])};
160+
window.lintrk.q=[]
161+
}
162+
163+
var s = document.getElementsByTagName("script")[0];
164+
var b = document.createElement("script");
165+
b.type = "text/javascript";b.async = true;
166+
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
167+
s.parentNode.insertBefore(b, s);
168+
})(window.lintrk);`
169+
}}
170+
/>
171+
172+
<noscript>
173+
<img
174+
height="1"
175+
width="1"
176+
style={{ display: "none" }}
177+
alt=""
178+
src={`https://px.ads.linkedin.com/collect/?pid=${linkedInInsightId}&fmt=gif`}
179+
/>
180+
</noscript>
181+
</>
182+
)}
117183
</body>
118184
</Html>
119185
);

0 commit comments

Comments
 (0)