@shware/analytics 2.9.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/server/index.cjs +37 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +7 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.mjs +10 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/linkedin-conversions-api.cjs +84 -0
- package/dist/server/linkedin-conversions-api.cjs.map +1 -0
- package/dist/server/linkedin-conversions-api.d.cts +56 -0
- package/dist/server/linkedin-conversions-api.d.ts +56 -0
- package/dist/server/linkedin-conversions-api.mjs +59 -0
- package/dist/server/linkedin-conversions-api.mjs.map +1 -0
- package/dist/third-parties/linkedin-insight-tag.cjs +32 -0
- package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -0
- package/dist/third-parties/linkedin-insight-tag.d.cts +3 -0
- package/dist/third-parties/linkedin-insight-tag.d.ts +3 -0
- package/dist/third-parties/linkedin-insight-tag.mjs +7 -0
- package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -0
- package/dist/track/lintrk.cjs +19 -0
- package/dist/track/lintrk.cjs.map +1 -0
- package/dist/track/lintrk.d.cts +8 -0
- package/dist/track/lintrk.d.ts +8 -0
- package/dist/track/lintrk.mjs +1 -0
- package/dist/track/lintrk.mjs.map +1 -0
- package/package.json +5 -10
package/README.md
CHANGED
|
@@ -60,3 +60,4 @@ function Button() {
|
|
|
60
60
|
## Third Parties Advices
|
|
61
61
|
|
|
62
62
|
- reddit: We strongly recommend using the Reddit Pixel and Conversions API (CAPI) together.
|
|
63
|
+
- linkedin: If we receive an Insight Tag event and a Conversions API event from the same account with the same eventId, we discard the Conversions API event and count only the Insight Tag event in campaign reporting.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/server/index.ts
|
|
21
|
+
var server_exports = {};
|
|
22
|
+
__export(server_exports, {
|
|
23
|
+
sendLinkedinEvents: () => import_linkedin_conversions_api.sendEvents,
|
|
24
|
+
sendMetaEvents: () => import_meta_conversions_api.sendEvents,
|
|
25
|
+
sendRedditEvents: () => import_reddit_conversions_api.sendEvents
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(server_exports);
|
|
28
|
+
var import_meta_conversions_api = require("./meta-conversions-api.cjs");
|
|
29
|
+
var import_reddit_conversions_api = require("./reddit-conversions-api.cjs");
|
|
30
|
+
var import_linkedin_conversions_api = require("./linkedin-conversions-api.cjs");
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
sendLinkedinEvents,
|
|
34
|
+
sendMetaEvents,
|
|
35
|
+
sendRedditEvents
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/index.ts"],"sourcesContent":["export { sendEvents as sendMetaEvents } from './meta-conversions-api';\nexport { sendEvents as sendRedditEvents } from './reddit-conversions-api';\nexport { sendEvents as sendLinkedinEvents } from './linkedin-conversions-api';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA6C;AAC7C,oCAA+C;AAC/C,sCAAiD;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { sendEvents as sendMetaEvents } from './meta-conversions-api.cjs';
|
|
2
|
+
export { sendEvents as sendRedditEvents } from './reddit-conversions-api.cjs';
|
|
3
|
+
export { sendEvents as sendLinkedinEvents } from './linkedin-conversions-api.cjs';
|
|
4
|
+
import 'facebook-nodejs-business-sdk';
|
|
5
|
+
import '../track/types.cjs';
|
|
6
|
+
import '../track/gtag.cjs';
|
|
7
|
+
import '../track/rdt.cjs';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { sendEvents as sendMetaEvents } from './meta-conversions-api.js';
|
|
2
|
+
export { sendEvents as sendRedditEvents } from './reddit-conversions-api.js';
|
|
3
|
+
export { sendEvents as sendLinkedinEvents } from './linkedin-conversions-api.js';
|
|
4
|
+
import 'facebook-nodejs-business-sdk';
|
|
5
|
+
import '../track/types.js';
|
|
6
|
+
import '../track/gtag.js';
|
|
7
|
+
import '../track/rdt.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/server/index.ts
|
|
2
|
+
import { sendEvents } from "./meta-conversions-api.mjs";
|
|
3
|
+
import { sendEvents as sendEvents2 } from "./reddit-conversions-api.mjs";
|
|
4
|
+
import { sendEvents as sendEvents3 } from "./linkedin-conversions-api.mjs";
|
|
5
|
+
export {
|
|
6
|
+
sendEvents3 as sendLinkedinEvents,
|
|
7
|
+
sendEvents as sendMetaEvents,
|
|
8
|
+
sendEvents2 as sendRedditEvents
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/index.ts"],"sourcesContent":["export { sendEvents as sendMetaEvents } from './meta-conversions-api';\nexport { sendEvents as sendRedditEvents } from './reddit-conversions-api';\nexport { sendEvents as sendLinkedinEvents } from './linkedin-conversions-api';\n"],"mappings":";AAAA,SAAuB,kBAAsB;AAC7C,SAAuB,cAAdA,mBAAsC;AAC/C,SAAuB,cAAdA,mBAAwC;","names":["sendEvents"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/server/linkedin-conversions-api.ts
|
|
21
|
+
var linkedin_conversions_api_exports = {};
|
|
22
|
+
__export(linkedin_conversions_api_exports, {
|
|
23
|
+
sendEvents: () => sendEvents
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(linkedin_conversions_api_exports);
|
|
26
|
+
var import_crypto = require("crypto");
|
|
27
|
+
var import_field = require("../utils/field.cjs");
|
|
28
|
+
async function sendEvents(accessToken, conversions, events, data = {}) {
|
|
29
|
+
const eventNames = Object.keys(conversions);
|
|
30
|
+
const address = (0, import_field.getFirst)(data.address);
|
|
31
|
+
const userIds = [];
|
|
32
|
+
const externalIds = data.user_id ? [data.user_id] : void 0;
|
|
33
|
+
const userInfo = address ? {
|
|
34
|
+
firstName: address.first_name,
|
|
35
|
+
lastName: address.last_name,
|
|
36
|
+
countryCode: address.country
|
|
37
|
+
} : void 0;
|
|
38
|
+
if (data.email) {
|
|
39
|
+
const email = (0, import_field.getFirst)(data.email);
|
|
40
|
+
if (email)
|
|
41
|
+
userIds.push({
|
|
42
|
+
idType: "SHA256_EMAIL",
|
|
43
|
+
idValue: (0, import_crypto.createHash)("sha256").update(email).digest("hex")
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const dto = {
|
|
47
|
+
elements: events.filter((event) => eventNames.includes(event.name)).map((event) => {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
return {
|
|
50
|
+
eventId: event.id,
|
|
51
|
+
conversion: `urn:lla:llaPartnerConversion:${conversions[event.name]}`,
|
|
52
|
+
conversionHappenedAt: Date.now(),
|
|
53
|
+
conversionValue: {
|
|
54
|
+
currencyCode: ((_b = (_a = event.properties) == null ? void 0 : _a.currency) == null ? void 0 : _b.toUpperCase()) ?? "USD",
|
|
55
|
+
amount: ((_d = (_c = event.properties) == null ? void 0 : _c.value) == null ? void 0 : _d.toString()) ?? "0"
|
|
56
|
+
},
|
|
57
|
+
user: {
|
|
58
|
+
userIds,
|
|
59
|
+
externalIds,
|
|
60
|
+
userInfo
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
if (dto.elements.length === 0) return;
|
|
66
|
+
const response = await fetch("https://api.linkedin.com/rest/conversionEvents", {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: `Bearer ${accessToken}`,
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
"LinkedIn-Version": "202509",
|
|
72
|
+
"X-Restli-Protocol-Version": "2.0.0"
|
|
73
|
+
},
|
|
74
|
+
body: JSON.stringify(dto)
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
console.error("Failed to send LinkedIn conversion events:", await response.text());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
sendEvents
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=linkedin-conversions-api.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/linkedin-conversions-api.ts"],"sourcesContent":["/**\n * Conversions API Payload Builder: https://www.linkedin.com/developers/payload-builder\n * https://learn.microsoft.com/en-us/linkedin/marketing/conversions/conversions-overview?view=li-lms-2025-09\n */\nimport { createHash } from 'crypto';\nimport { getFirst } from '../utils/field';\nimport type { EventName, TrackEvent, UserProvidedData } from '../track/types';\n\ntype UserIdType =\n | 'SHA256_EMAIL'\n | 'LINKEDIN_FIRST_PARTY_ADS_TRACKING_UUID'\n | 'ACXIOM_ID'\n | 'ORACLE_MOAT_ID';\n\nexport interface CreateLinkedinEventDTO {\n /**\n * For any conversion that you want to send through multiple methods, such as Insight Tag and\n * Conversions API, you must create a conversion rule for each data source (browser and server).\n * Then, you can implement a logic to pick up the eventId from the browser and send it with the\n * corresponding event from your server. If we receive an Insight Tag event and a Conversions API\n * event from the same account with the same eventId, we discard the Conversions API event and\n * count only the Insight Tag event in campaign reporting.\n */\n eventId?: string;\n\n /**\n * Replace <id> with the conversion ID extracted when creating the conversion rule\n * (e.g. urn:lla:llaPartnerConversion:<id>).\n */\n conversion: `urn:lla:llaPartnerConversion:${number}`;\n\n /** Epoch timestamp in milliseconds at which the conversion event happened. */\n conversionHappenedAt: number;\n conversionValue: { currencyCode: string; amount: string };\n user: {\n userIds: { idType: UserIdType; idValue: string }[];\n userInfo?: {\n firstName?: string;\n lastName?: string;\n companyName?: string;\n countryCode?: string;\n title?: string;\n };\n\n /**\n * The maximum supported size of the list is 1 at the moment. If the list contains multiple\n * values, only the first value will be used.\n */\n externalIds?: [string, ...string[]];\n\n /**\n * This is generated when users submit the Linkedin Lead-gen form\n * (e.g. urn:li:leadGenFormResponse:<id>).\n */\n lead?: `urn:li:leadGenFormResponse:${string}`;\n };\n}\n\nexport interface CreateMultipleLinkedinEventsDTO {\n elements: CreateLinkedinEventDTO[];\n}\n\nexport type Conversions = Record<EventName, number>;\n\nexport async function sendEvents(\n accessToken: string,\n conversions: Conversions,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n events: TrackEvent<any>[],\n data: UserProvidedData = {}\n) {\n const eventNames = Object.keys(conversions);\n const address = getFirst(data.address);\n const userIds: { idType: UserIdType; idValue: string }[] = [];\n const externalIds: [string, ...string[]] | undefined = data.user_id ? [data.user_id] : undefined;\n const userInfo = address\n ? {\n firstName: address.first_name,\n lastName: address.last_name,\n countryCode: address.country,\n }\n : undefined;\n\n if (data.email) {\n const email = getFirst(data.email);\n if (email)\n userIds.push({\n idType: 'SHA256_EMAIL',\n idValue: createHash('sha256').update(email).digest('hex'),\n });\n }\n\n // todo: add LINKEDIN_FIRST_PARTY_ADS_TRACKING_UUID\n\n const dto: CreateMultipleLinkedinEventsDTO = {\n elements: events\n .filter((event) => eventNames.includes(event.name))\n .map((event) => ({\n eventId: event.id,\n conversion: `urn:lla:llaPartnerConversion:${conversions[event.name]}`,\n conversionHappenedAt: Date.now(),\n conversionValue: {\n currencyCode: event.properties?.currency?.toUpperCase() ?? 'USD',\n amount: event.properties?.value?.toString() ?? '0',\n },\n user: {\n userIds,\n externalIds,\n userInfo,\n },\n })),\n };\n\n if (dto.elements.length === 0) return;\n const response = await fetch('https://api.linkedin.com/rest/conversionEvents', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json',\n 'LinkedIn-Version': '202509',\n 'X-Restli-Protocol-Version': '2.0.0',\n },\n body: JSON.stringify(dto),\n });\n\n if (!response.ok) {\n console.error('Failed to send LinkedIn conversion events:', await response.text());\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA2B;AAC3B,mBAAyB;AA2DzB,eAAsB,WACpB,aACA,aAEA,QACA,OAAyB,CAAC,GAC1B;AACA,QAAM,aAAa,OAAO,KAAK,WAAW;AAC1C,QAAM,cAAU,uBAAS,KAAK,OAAO;AACrC,QAAM,UAAqD,CAAC;AAC5D,QAAM,cAAiD,KAAK,UAAU,CAAC,KAAK,OAAO,IAAI;AACvF,QAAM,WAAW,UACb;AAAA,IACE,WAAW,QAAQ;AAAA,IACnB,UAAU,QAAQ;AAAA,IAClB,aAAa,QAAQ;AAAA,EACvB,IACA;AAEJ,MAAI,KAAK,OAAO;AACd,UAAM,YAAQ,uBAAS,KAAK,KAAK;AACjC,QAAI;AACF,cAAQ,KAAK;AAAA,QACX,QAAQ;AAAA,QACR,aAAS,0BAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA,MAC1D,CAAC;AAAA,EACL;AAIA,QAAM,MAAuC;AAAA,IAC3C,UAAU,OACP,OAAO,CAAC,UAAU,WAAW,SAAS,MAAM,IAAI,CAAC,EACjD,IAAI,CAAC,UAAO;AAjGnB;AAiGuB;AAAA,QACf,SAAS,MAAM;AAAA,QACf,YAAY,gCAAgC,YAAY,MAAM,IAAI,CAAC;AAAA,QACnE,sBAAsB,KAAK,IAAI;AAAA,QAC/B,iBAAiB;AAAA,UACf,gBAAc,iBAAM,eAAN,mBAAkB,aAAlB,mBAA4B,kBAAiB;AAAA,UAC3D,UAAQ,iBAAM,eAAN,mBAAkB,UAAlB,mBAAyB,eAAc;AAAA,QACjD;AAAA,QACA,MAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,KAAE;AAAA,EACN;AAEA,MAAI,IAAI,SAAS,WAAW,EAAG;AAC/B,QAAM,WAAW,MAAM,MAAM,kDAAkD;AAAA,IAC7E,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,UAAU,WAAW;AAAA,MACpC,gBAAgB;AAAA,MAChB,oBAAoB;AAAA,MACpB,6BAA6B;AAAA,IAC/B;AAAA,IACA,MAAM,KAAK,UAAU,GAAG;AAAA,EAC1B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,YAAQ,MAAM,8CAA8C,MAAM,SAAS,KAAK,CAAC;AAAA,EACnF;AACF;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EventName, TrackEvent, UserProvidedData } from '../track/types.cjs';
|
|
2
|
+
import '../track/gtag.cjs';
|
|
3
|
+
|
|
4
|
+
type UserIdType = 'SHA256_EMAIL' | 'LINKEDIN_FIRST_PARTY_ADS_TRACKING_UUID' | 'ACXIOM_ID' | 'ORACLE_MOAT_ID';
|
|
5
|
+
interface CreateLinkedinEventDTO {
|
|
6
|
+
/**
|
|
7
|
+
* For any conversion that you want to send through multiple methods, such as Insight Tag and
|
|
8
|
+
* Conversions API, you must create a conversion rule for each data source (browser and server).
|
|
9
|
+
* Then, you can implement a logic to pick up the eventId from the browser and send it with the
|
|
10
|
+
* corresponding event from your server. If we receive an Insight Tag event and a Conversions API
|
|
11
|
+
* event from the same account with the same eventId, we discard the Conversions API event and
|
|
12
|
+
* count only the Insight Tag event in campaign reporting.
|
|
13
|
+
*/
|
|
14
|
+
eventId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Replace <id> with the conversion ID extracted when creating the conversion rule
|
|
17
|
+
* (e.g. urn:lla:llaPartnerConversion:<id>).
|
|
18
|
+
*/
|
|
19
|
+
conversion: `urn:lla:llaPartnerConversion:${number}`;
|
|
20
|
+
/** Epoch timestamp in milliseconds at which the conversion event happened. */
|
|
21
|
+
conversionHappenedAt: number;
|
|
22
|
+
conversionValue: {
|
|
23
|
+
currencyCode: string;
|
|
24
|
+
amount: string;
|
|
25
|
+
};
|
|
26
|
+
user: {
|
|
27
|
+
userIds: {
|
|
28
|
+
idType: UserIdType;
|
|
29
|
+
idValue: string;
|
|
30
|
+
}[];
|
|
31
|
+
userInfo?: {
|
|
32
|
+
firstName?: string;
|
|
33
|
+
lastName?: string;
|
|
34
|
+
companyName?: string;
|
|
35
|
+
countryCode?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The maximum supported size of the list is 1 at the moment. If the list contains multiple
|
|
40
|
+
* values, only the first value will be used.
|
|
41
|
+
*/
|
|
42
|
+
externalIds?: [string, ...string[]];
|
|
43
|
+
/**
|
|
44
|
+
* This is generated when users submit the Linkedin Lead-gen form
|
|
45
|
+
* (e.g. urn:li:leadGenFormResponse:<id>).
|
|
46
|
+
*/
|
|
47
|
+
lead?: `urn:li:leadGenFormResponse:${string}`;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface CreateMultipleLinkedinEventsDTO {
|
|
51
|
+
elements: CreateLinkedinEventDTO[];
|
|
52
|
+
}
|
|
53
|
+
type Conversions = Record<EventName, number>;
|
|
54
|
+
declare function sendEvents(accessToken: string, conversions: Conversions, events: TrackEvent<any>[], data?: UserProvidedData): Promise<void>;
|
|
55
|
+
|
|
56
|
+
export { type Conversions, type CreateLinkedinEventDTO, type CreateMultipleLinkedinEventsDTO, sendEvents };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EventName, TrackEvent, UserProvidedData } from '../track/types.js';
|
|
2
|
+
import '../track/gtag.js';
|
|
3
|
+
|
|
4
|
+
type UserIdType = 'SHA256_EMAIL' | 'LINKEDIN_FIRST_PARTY_ADS_TRACKING_UUID' | 'ACXIOM_ID' | 'ORACLE_MOAT_ID';
|
|
5
|
+
interface CreateLinkedinEventDTO {
|
|
6
|
+
/**
|
|
7
|
+
* For any conversion that you want to send through multiple methods, such as Insight Tag and
|
|
8
|
+
* Conversions API, you must create a conversion rule for each data source (browser and server).
|
|
9
|
+
* Then, you can implement a logic to pick up the eventId from the browser and send it with the
|
|
10
|
+
* corresponding event from your server. If we receive an Insight Tag event and a Conversions API
|
|
11
|
+
* event from the same account with the same eventId, we discard the Conversions API event and
|
|
12
|
+
* count only the Insight Tag event in campaign reporting.
|
|
13
|
+
*/
|
|
14
|
+
eventId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Replace <id> with the conversion ID extracted when creating the conversion rule
|
|
17
|
+
* (e.g. urn:lla:llaPartnerConversion:<id>).
|
|
18
|
+
*/
|
|
19
|
+
conversion: `urn:lla:llaPartnerConversion:${number}`;
|
|
20
|
+
/** Epoch timestamp in milliseconds at which the conversion event happened. */
|
|
21
|
+
conversionHappenedAt: number;
|
|
22
|
+
conversionValue: {
|
|
23
|
+
currencyCode: string;
|
|
24
|
+
amount: string;
|
|
25
|
+
};
|
|
26
|
+
user: {
|
|
27
|
+
userIds: {
|
|
28
|
+
idType: UserIdType;
|
|
29
|
+
idValue: string;
|
|
30
|
+
}[];
|
|
31
|
+
userInfo?: {
|
|
32
|
+
firstName?: string;
|
|
33
|
+
lastName?: string;
|
|
34
|
+
companyName?: string;
|
|
35
|
+
countryCode?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The maximum supported size of the list is 1 at the moment. If the list contains multiple
|
|
40
|
+
* values, only the first value will be used.
|
|
41
|
+
*/
|
|
42
|
+
externalIds?: [string, ...string[]];
|
|
43
|
+
/**
|
|
44
|
+
* This is generated when users submit the Linkedin Lead-gen form
|
|
45
|
+
* (e.g. urn:li:leadGenFormResponse:<id>).
|
|
46
|
+
*/
|
|
47
|
+
lead?: `urn:li:leadGenFormResponse:${string}`;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface CreateMultipleLinkedinEventsDTO {
|
|
51
|
+
elements: CreateLinkedinEventDTO[];
|
|
52
|
+
}
|
|
53
|
+
type Conversions = Record<EventName, number>;
|
|
54
|
+
declare function sendEvents(accessToken: string, conversions: Conversions, events: TrackEvent<any>[], data?: UserProvidedData): Promise<void>;
|
|
55
|
+
|
|
56
|
+
export { type Conversions, type CreateLinkedinEventDTO, type CreateMultipleLinkedinEventsDTO, sendEvents };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/server/linkedin-conversions-api.ts
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
import { getFirst } from "../utils/field.mjs";
|
|
4
|
+
async function sendEvents(accessToken, conversions, events, data = {}) {
|
|
5
|
+
const eventNames = Object.keys(conversions);
|
|
6
|
+
const address = getFirst(data.address);
|
|
7
|
+
const userIds = [];
|
|
8
|
+
const externalIds = data.user_id ? [data.user_id] : void 0;
|
|
9
|
+
const userInfo = address ? {
|
|
10
|
+
firstName: address.first_name,
|
|
11
|
+
lastName: address.last_name,
|
|
12
|
+
countryCode: address.country
|
|
13
|
+
} : void 0;
|
|
14
|
+
if (data.email) {
|
|
15
|
+
const email = getFirst(data.email);
|
|
16
|
+
if (email)
|
|
17
|
+
userIds.push({
|
|
18
|
+
idType: "SHA256_EMAIL",
|
|
19
|
+
idValue: createHash("sha256").update(email).digest("hex")
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const dto = {
|
|
23
|
+
elements: events.filter((event) => eventNames.includes(event.name)).map((event) => {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
return {
|
|
26
|
+
eventId: event.id,
|
|
27
|
+
conversion: `urn:lla:llaPartnerConversion:${conversions[event.name]}`,
|
|
28
|
+
conversionHappenedAt: Date.now(),
|
|
29
|
+
conversionValue: {
|
|
30
|
+
currencyCode: ((_b = (_a = event.properties) == null ? void 0 : _a.currency) == null ? void 0 : _b.toUpperCase()) ?? "USD",
|
|
31
|
+
amount: ((_d = (_c = event.properties) == null ? void 0 : _c.value) == null ? void 0 : _d.toString()) ?? "0"
|
|
32
|
+
},
|
|
33
|
+
user: {
|
|
34
|
+
userIds,
|
|
35
|
+
externalIds,
|
|
36
|
+
userInfo
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
if (dto.elements.length === 0) return;
|
|
42
|
+
const response = await fetch("https://api.linkedin.com/rest/conversionEvents", {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: {
|
|
45
|
+
Authorization: `Bearer ${accessToken}`,
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
"LinkedIn-Version": "202509",
|
|
48
|
+
"X-Restli-Protocol-Version": "2.0.0"
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify(dto)
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
console.error("Failed to send LinkedIn conversion events:", await response.text());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
sendEvents
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=linkedin-conversions-api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/linkedin-conversions-api.ts"],"sourcesContent":["/**\n * Conversions API Payload Builder: https://www.linkedin.com/developers/payload-builder\n * https://learn.microsoft.com/en-us/linkedin/marketing/conversions/conversions-overview?view=li-lms-2025-09\n */\nimport { createHash } from 'crypto';\nimport { getFirst } from '../utils/field';\nimport type { EventName, TrackEvent, UserProvidedData } from '../track/types';\n\ntype UserIdType =\n | 'SHA256_EMAIL'\n | 'LINKEDIN_FIRST_PARTY_ADS_TRACKING_UUID'\n | 'ACXIOM_ID'\n | 'ORACLE_MOAT_ID';\n\nexport interface CreateLinkedinEventDTO {\n /**\n * For any conversion that you want to send through multiple methods, such as Insight Tag and\n * Conversions API, you must create a conversion rule for each data source (browser and server).\n * Then, you can implement a logic to pick up the eventId from the browser and send it with the\n * corresponding event from your server. If we receive an Insight Tag event and a Conversions API\n * event from the same account with the same eventId, we discard the Conversions API event and\n * count only the Insight Tag event in campaign reporting.\n */\n eventId?: string;\n\n /**\n * Replace <id> with the conversion ID extracted when creating the conversion rule\n * (e.g. urn:lla:llaPartnerConversion:<id>).\n */\n conversion: `urn:lla:llaPartnerConversion:${number}`;\n\n /** Epoch timestamp in milliseconds at which the conversion event happened. */\n conversionHappenedAt: number;\n conversionValue: { currencyCode: string; amount: string };\n user: {\n userIds: { idType: UserIdType; idValue: string }[];\n userInfo?: {\n firstName?: string;\n lastName?: string;\n companyName?: string;\n countryCode?: string;\n title?: string;\n };\n\n /**\n * The maximum supported size of the list is 1 at the moment. If the list contains multiple\n * values, only the first value will be used.\n */\n externalIds?: [string, ...string[]];\n\n /**\n * This is generated when users submit the Linkedin Lead-gen form\n * (e.g. urn:li:leadGenFormResponse:<id>).\n */\n lead?: `urn:li:leadGenFormResponse:${string}`;\n };\n}\n\nexport interface CreateMultipleLinkedinEventsDTO {\n elements: CreateLinkedinEventDTO[];\n}\n\nexport type Conversions = Record<EventName, number>;\n\nexport async function sendEvents(\n accessToken: string,\n conversions: Conversions,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n events: TrackEvent<any>[],\n data: UserProvidedData = {}\n) {\n const eventNames = Object.keys(conversions);\n const address = getFirst(data.address);\n const userIds: { idType: UserIdType; idValue: string }[] = [];\n const externalIds: [string, ...string[]] | undefined = data.user_id ? [data.user_id] : undefined;\n const userInfo = address\n ? {\n firstName: address.first_name,\n lastName: address.last_name,\n countryCode: address.country,\n }\n : undefined;\n\n if (data.email) {\n const email = getFirst(data.email);\n if (email)\n userIds.push({\n idType: 'SHA256_EMAIL',\n idValue: createHash('sha256').update(email).digest('hex'),\n });\n }\n\n // todo: add LINKEDIN_FIRST_PARTY_ADS_TRACKING_UUID\n\n const dto: CreateMultipleLinkedinEventsDTO = {\n elements: events\n .filter((event) => eventNames.includes(event.name))\n .map((event) => ({\n eventId: event.id,\n conversion: `urn:lla:llaPartnerConversion:${conversions[event.name]}`,\n conversionHappenedAt: Date.now(),\n conversionValue: {\n currencyCode: event.properties?.currency?.toUpperCase() ?? 'USD',\n amount: event.properties?.value?.toString() ?? '0',\n },\n user: {\n userIds,\n externalIds,\n userInfo,\n },\n })),\n };\n\n if (dto.elements.length === 0) return;\n const response = await fetch('https://api.linkedin.com/rest/conversionEvents', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json',\n 'LinkedIn-Version': '202509',\n 'X-Restli-Protocol-Version': '2.0.0',\n },\n body: JSON.stringify(dto),\n });\n\n if (!response.ok) {\n console.error('Failed to send LinkedIn conversion events:', await response.text());\n }\n}\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AA2DzB,eAAsB,WACpB,aACA,aAEA,QACA,OAAyB,CAAC,GAC1B;AACA,QAAM,aAAa,OAAO,KAAK,WAAW;AAC1C,QAAM,UAAU,SAAS,KAAK,OAAO;AACrC,QAAM,UAAqD,CAAC;AAC5D,QAAM,cAAiD,KAAK,UAAU,CAAC,KAAK,OAAO,IAAI;AACvF,QAAM,WAAW,UACb;AAAA,IACE,WAAW,QAAQ;AAAA,IACnB,UAAU,QAAQ;AAAA,IAClB,aAAa,QAAQ;AAAA,EACvB,IACA;AAEJ,MAAI,KAAK,OAAO;AACd,UAAM,QAAQ,SAAS,KAAK,KAAK;AACjC,QAAI;AACF,cAAQ,KAAK;AAAA,QACX,QAAQ;AAAA,QACR,SAAS,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA,MAC1D,CAAC;AAAA,EACL;AAIA,QAAM,MAAuC;AAAA,IAC3C,UAAU,OACP,OAAO,CAAC,UAAU,WAAW,SAAS,MAAM,IAAI,CAAC,EACjD,IAAI,CAAC,UAAO;AAjGnB;AAiGuB;AAAA,QACf,SAAS,MAAM;AAAA,QACf,YAAY,gCAAgC,YAAY,MAAM,IAAI,CAAC;AAAA,QACnE,sBAAsB,KAAK,IAAI;AAAA,QAC/B,iBAAiB;AAAA,UACf,gBAAc,iBAAM,eAAN,mBAAkB,aAAlB,mBAA4B,kBAAiB;AAAA,UAC3D,UAAQ,iBAAM,eAAN,mBAAkB,UAAlB,mBAAyB,eAAc;AAAA,QACjD;AAAA,QACA,MAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,KAAE;AAAA,EACN;AAEA,MAAI,IAAI,SAAS,WAAW,EAAG;AAC/B,QAAM,WAAW,MAAM,MAAM,kDAAkD;AAAA,IAC7E,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,UAAU,WAAW;AAAA,MACpC,gBAAgB;AAAA,MAChB,oBAAoB;AAAA,MACpB,6BAA6B;AAAA,IAC/B;AAAA,IACA,MAAM,KAAK,UAAU,GAAG;AAAA,EAC1B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,YAAQ,MAAM,8CAA8C,MAAM,SAAS,KAAK,CAAC;AAAA,EACnF;AACF;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/third-parties/linkedin-insight-tag.ts
|
|
21
|
+
var linkedin_insight_tag_exports = {};
|
|
22
|
+
__export(linkedin_insight_tag_exports, {
|
|
23
|
+
sendLinkedinEvent: () => sendLinkedinEvent
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(linkedin_insight_tag_exports);
|
|
26
|
+
function sendLinkedinEvent() {
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
sendLinkedinEvent
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=linkedin-insight-tag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/third-parties/linkedin-insight-tag.ts"],"sourcesContent":["export function sendLinkedinEvent() {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,oBAAoB;AAAC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/third-parties/linkedin-insight-tag.ts"],"sourcesContent":["export function sendLinkedinEvent() {}\n"],"mappings":";AAAO,SAAS,oBAAoB;AAAC;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/track/lintrk.ts
|
|
17
|
+
var lintrk_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(lintrk_exports);
|
|
19
|
+
//# sourceMappingURL=lintrk.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/track/lintrk.ts"],"sourcesContent":["export interface Lintrk {\n lintrk(event: 'track', params: { conversion_id: number; event_id?: string }): void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=lintrk.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/analytics",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -48,15 +48,10 @@
|
|
|
48
48
|
"import": "./dist/third-parties/index.mjs",
|
|
49
49
|
"require": "./dist/third-parties/index.cjs"
|
|
50
50
|
},
|
|
51
|
-
"./server
|
|
52
|
-
"types": "./dist/server/
|
|
53
|
-
"import": "./dist/server/
|
|
54
|
-
"require": "./dist/server/
|
|
55
|
-
},
|
|
56
|
-
"./server/reddit-conversions-api": {
|
|
57
|
-
"types": "./dist/server/reddit-conversions-api.d.ts",
|
|
58
|
-
"import": "./dist/server/reddit-conversions-api.mjs",
|
|
59
|
-
"require": "./dist/server/reddit-conversions-api.cjs"
|
|
51
|
+
"./server": {
|
|
52
|
+
"types": "./dist/server/index.d.ts",
|
|
53
|
+
"import": "./dist/server/index.mjs",
|
|
54
|
+
"require": "./dist/server/index.cjs"
|
|
60
55
|
}
|
|
61
56
|
},
|
|
62
57
|
"files": [
|