|
| 1 | +--- |
| 2 | +title: LinkedIn Insight Tag |
| 3 | +description: Use the LinkedIn Insight Tag in your Nuxt app to track conversions, retarget visitors, and learn about your audience. |
| 4 | +links: |
| 5 | +- label: Source |
| 6 | + icon: i-simple-icons-github |
| 7 | + to: https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/linkedin-insight.ts |
| 8 | + size: xs |
| 9 | +--- |
| 10 | + |
| 11 | +The [LinkedIn Insight Tag](https://business.linkedin.com/marketing-solutions/insight-tag) is a lightweight JavaScript snippet for conversion tracking, retargeting, and audience insights on LinkedIn Ads campaigns. |
| 12 | + |
| 13 | +Nuxt Scripts provides a registry script composable [`useScriptLinkedInInsight()`{lang="ts"}](/scripts/linkedin-insight) to integrate it in your Nuxt app. |
| 14 | + |
| 15 | +::script-stats |
| 16 | +:: |
| 17 | + |
| 18 | +::script-docs |
| 19 | +:: |
| 20 | + |
| 21 | +::script-types |
| 22 | +:: |
| 23 | + |
| 24 | +## Examples |
| 25 | + |
| 26 | +### Tracking a conversion |
| 27 | + |
| 28 | +```vue |
| 29 | +<script setup lang="ts"> |
| 30 | +const { proxy } = useScriptLinkedInInsight({ |
| 31 | + id: '111143', |
| 32 | +}) |
| 33 | +
|
| 34 | +function trackPurchase() { |
| 35 | + proxy.lintrk('track', { conversion_id: 1111111177 }) |
| 36 | +} |
| 37 | +</script> |
| 38 | +``` |
| 39 | + |
| 40 | +### Per-event deduplication with the Conversions API |
| 41 | + |
| 42 | +When you also send conversions through LinkedIn's server-side Conversions API, pass the same `event_id` to both. LinkedIn discards the server-side duplicate and counts the Insight Tag event. See [LinkedIn deduplication](https://learn.microsoft.com/en-us/linkedin/marketing/conversions/deduplication?view=li-lms-2026-01). |
| 43 | + |
| 44 | +```vue |
| 45 | +<script setup lang="ts"> |
| 46 | +const { proxy } = useScriptLinkedInInsight({ |
| 47 | + id: '111143', |
| 48 | +}) |
| 49 | +
|
| 50 | +function trackSignup() { |
| 51 | + const eventId = crypto.randomUUID() |
| 52 | + proxy.lintrk('track', { conversion_id: 1111111177, event_id: eventId }) |
| 53 | + // Send the same eventId to your server-side Conversions API call. |
| 54 | +} |
| 55 | +</script> |
| 56 | +``` |
| 57 | + |
| 58 | +### Page-load conversion deduplication |
| 59 | + |
| 60 | +For dedup on the auto-fired page-view, set `eventId` at registration. The composable assigns `window._linkedin_event_id` *before* the Insight Tag base code runs, so the page-view URL includes `&eventId=…` automatically. |
| 61 | + |
| 62 | +```vue |
| 63 | +<script setup lang="ts"> |
| 64 | +const { proxy } = useScriptLinkedInInsight({ |
| 65 | + id: '111143', |
| 66 | + eventId: 'page-load-event-id-123', |
| 67 | +}) |
| 68 | +</script> |
| 69 | +``` |
| 70 | + |
| 71 | +### Enhanced matching with `setUserData` |
| 72 | + |
| 73 | +Pass plain email; the Insight Tag SHA-256 hashes it on-device. See [LinkedIn enhanced matching](https://www.linkedin.com/help/lms/answer/a6246095). |
| 74 | + |
| 75 | +```vue |
| 76 | +<script setup lang="ts"> |
| 77 | +const { proxy } = useScriptLinkedInInsight({ |
| 78 | + id: '111143', |
| 79 | +}) |
| 80 | +
|
| 81 | +function onSignupSuccess(email: string) { |
| 82 | + proxy.lintrk('setUserData', { email }) |
| 83 | +} |
| 84 | +</script> |
| 85 | +``` |
| 86 | + |
| 87 | +The Insight Tag stores the hashed email in `localStorage["li_hem"]` and transmits it on the next page-view via a separate POST to `https://px.ads.linkedin.com/wa/...` (the WebsiteActions gateway). The `/collect` URL of the page-view immediately following `setUserData` does not carry it; LinkedIn picks it up on the next full page load when the bootstrap reads it back from `localStorage`. |
| 88 | + |
| 89 | +### SPA virtual page views |
| 90 | + |
| 91 | +By default, the Insight Tag fires a page-view exactly once when the script loads, so SPA route changes go untracked. Opt in to per-route tracking with `enableAutoSpaTracking`: |
| 92 | + |
| 93 | +```vue |
| 94 | +<script setup lang="ts"> |
| 95 | +useScriptLinkedInInsight({ |
| 96 | + id: '111143', |
| 97 | + enableAutoSpaTracking: true, |
| 98 | +}) |
| 99 | +</script> |
| 100 | +``` |
| 101 | + |
| 102 | +When enabled, the composable suppresses the script's built-in auto-page-view (via `window._wait_for_lintrk = true`) and fires `lintrk('track')`{lang="ts"} on Nuxt's `page:finish` hook instead, so each route (including the initial page) produces exactly one `/collect` beacon. |
| 103 | + |
| 104 | +### Multiple Partner IDs |
| 105 | + |
| 106 | +If you need to push more than one Partner ID onto `window._linkedin_data_partner_ids`, pass an array. The composable promotes the first ID to the primary `_linkedin_partner_id` global. |
| 107 | + |
| 108 | +```vue |
| 109 | +<script setup lang="ts"> |
| 110 | +useScriptLinkedInInsight({ |
| 111 | + id: ['111143', '111154'], |
| 112 | +}) |
| 113 | +</script> |
| 114 | +``` |
0 commit comments