Fire the LinkedIn Insight Tag only after visitors accept targeting cookies

Tag every script of the LinkedIn Insight Tag with targeting, and by default TermsFeed Free Cookie Consent holds the Insight Tag until the visitor accepts advertising cookies. Before the answer, by default, no request reaches LinkedIn and no LinkedIn cookie is stored. The moment the visitor accepts, the Insight Tag runs on the same page, with no reload, and records the page view.

The Insight Tag identifies visitors for conversion tracking, retargeting, and audience reports, so it needs consent first for visitors in the EU and the UK. The setup takes about 10 minutes. Have the Cookie Consent code from the TermsFeed generator on your pages and access to LinkedIn Campaign Manager before you start.

Tag the LinkedIn Insight Tag with targeting

LinkedIn shows the Insight Tag code only in Campaign Manager and asks you to copy the full code. Tagging changes the opening <script> tags and removes the <noscript> image, and the JavaScript stays as copied.

Copy the code from Campaign Manager, tag it, and paste it into your pages. Compare the Campaign Manager menu names with the LinkedIn help article Add the LinkedIn Insight Tag to your website.

  1. Go to your ad account in Campaign Manager, click Measure in the left menu, then click Signals manager.
  2. Click Insight Tag, then open the I will install the tag myself dropdown, and copy the code.
  3. Replace each opening <script> tag of the code with <script type="text/plain" data-cookie-consent="targeting">, and keep each closing </script> tag and the JavaScript between the tags unchanged.
  4. Delete any <noscript> element in the code.
  5. Paste the result into the pages of your domain. LinkedIn recommends the spot right before the closing </body> tag in the global footer of your site.

The tagged code runs from any place in the page markup, because run() starts on DOMContentLoaded. Keep the scripts in the order LinkedIn gives them, because the tagged scripts of one category run in page order. The script that sets the partner ID then runs before the script that loads insight.min.js. Read how tagged scripts run, and which attributes they keep, in Block Scripts Until Consent.

Where the LinkedIn conversion scripts go

Campaign Manager gives an event-specific conversion as a lintrk('track', ...) call or as an image pixel. Put a call that runs on page load, such as on a thank-you page, in a script tagged targeting below the Insight Tag scripts, so it runs after them. Call lintrk from a click handler only when window.lintrk exists, because the tagged Insight Tag defines it once the visitor accepts. Leave the image pixel out, because Cookie Consent holds only scripts.

The checks assume express consent with page_load_consent_levels left out or at the generator value ["strictly-necessary"], and the "I decline" button shown. Publish the change and clear any page cache before the check. Watch the Network tab for LinkedIn requests before and after the answer. Close every private window, then start the check in a new one, where no saved answer hides the consent banner.

  1. Open your site in that window of Chrome, open DevTools, and select the Network tab.
  2. Type licdn in the filter box and reload. No request appears while the consent banner shows. Repeat with the filter linkedin. In the Application tab, under Cookies, no LinkedIn cookie is listed for your domain.
  3. Clear the filter and click the "I agree" button. Requests to snap.licdn.com and px.ads.linkedin.com appear. LinkedIn lists both hosts for the Insight Tag in Troubleshoot the LinkedIn Insight Tag.
  4. Select the Application tab, open Cookies, and check that LinkedIn cookies, such as ln_or, are listed now on your domain. li_fat_id appears only after a visit from a click on a LinkedIn ad.
  5. Close every private window and open a new one. Open DevTools, type licdn in the Network filter, load your site, and click the "I decline" button. The filter stays empty, and so does linkedin when you switch to it. No LinkedIn cookie appears.

Cookies the LinkedIn Insight Tag sets

The Insight Tag stores cookies on your domain and on linkedin.com, including these from the LinkedIn cookie table. List them in your Cookies Policy under targeting cookies.

Cookie Domain Lifetime
li_fat_id Your domain 30 days
ln_or Your domain 1 day
bcookie linkedin.com 1 year
lidc linkedin.com 1 day
UserMatchHistory linkedin.com 30 days
li_sugr linkedin.com 90 days

Common mistakes with the LinkedIn Insight Tag

Check every page that carries the Insight Tag for each mistake. A LinkedIn request in your check before the answer comes from code that Cookie Consent does not hold, such as an untagged script or a copy another tool adds.

  • A <noscript> image stays in the page. A visitor with JavaScript turned off never sees the consent banner, because Cookie Consent is a script, and the image sends a request to px.ads.linkedin.com without consent. Your own check with JavaScript on never shows that request. Search the page source of each page for <noscript> near the Insight Tag, and delete the whole <noscript> element.
  • Only one script of the Insight Tag is tagged. An untagged script that loads insight.min.js sends a request to snap.licdn.com before the answer, while the script that sets the partner ID sends nothing by itself. Search the page source for each script of the Insight Tag, and check that it carries type="text/plain". Tag every script of the code.
  • A plugin, an app, or a tag manager adds the Insight Tag. That copy runs outside Cookie Consent, which holds only tagged scripts in your own markup. The licdn filter then shows a request before the answer, though your own copy is tagged. Remove the Insight Tag from that plugin, app, or tag manager, and keep the copy you tagged.
  • A conversion script stays untagged. The script calls lintrk before the tagged Insight Tag defines the function, so the Console tab shows an error and LinkedIn does not record a conversion. Search the page source for each conversion script and its data-cookie-consent attribute, and tag every one with targeting.
  • The Insight Tag is tagged with tracking. The Insight Tag serves advertising, but a tracking tag runs it for a visitor who accepts tracking cookies and refuses targeting cookies. Look for data-cookie-consent="tracking" on the Insight Tag scripts, and change it to targeting.
  • You expect a withdrawal to delete LinkedIn cookies. Cookie Consent does not delete cookies set by LinkedIn, so the Application tab still lists the LinkedIn cookies on your domain after the withdrawal. The Insight Tag itself stays held from the next page load on. Delete the LinkedIn cookies on your domain from a callback with the pattern in Rejecting Does Not Delete Cookies Already Set.

Events your server sends to the LinkedIn Conversions API never pass through the consent banner. Read why server-side event sending bypasses the consent banner in Vendor Recipes for Free Cookie Consent.