Skip to content

Instantly share code, notes, and snippets.

View otyeung's full-sized avatar

Dennis Yeung otyeung

View GitHub Profile
@otyeung
otyeung / lead_sync_validaiton.js
Created July 29, 2025 08:42
LinkedIn Lead Sync Webhook Validation code
async (event, steps) => {
// Validation request
if (event.query.challengeCode) {
const code = event.query.challengeCode;
const crypto = require('crypto');
const hmac = crypto.createHmac('sha256', process.env.client_secret);
const response = hmac.update(code).digest('hex');
$respond({
status: 200,
headers: {},
<script>
window.dataLayer = window.dataLayer || [];
function pushConversionEvent(CAPI_conversionRuleId, insightTag_conversionRuleId) {
// Generate unique event id that is passed to CAPI and Insight Tag for this instance
var unique_id = generateUUID();
// Fetch form data elements safely
var emailElement = document.getElementById('email');
if (emailElement) {
<script>
window.dataLayer = window.dataLayer || []
function pushConversionEvent(CAPI_conversionRuleId, insightTag_conversionRuleId) {
// Generate unique event id that is passed to CAPI and Insight Tag for this instance
var unique_id = generateUUID();
// Create the event object
var eventObject = {
event: 'CAPI Page View', // Replace your own event name if needed
<script>
// Generate an unique, random event ID for CAPI event de-duplication based on uuid v4 algorithm
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g,
function (c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
}
@otyeung
otyeung / li_fat_id_1p_data.js
Created June 10, 2024 10:19
li_fat_id_1p_data function in GTM Web Container
function li_fat_id_1p_data() {
// Function to get a cookie by name
function getCookie(name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) {
return match[2];
}
return '';
}
@otyeung
otyeung / li_fat_id.js
Created June 10, 2024 10:17
li_fat_id function in GTM Web Container
function li_fat_id() {
// Function to get a cookie by name
function getCookie(name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) {
return match[2];
}
return '';
}
@otyeung
otyeung / uuid.js
Created June 10, 2024 09:35
uuid function in GTM Web Container
function uuid() {
// UUID generator
// Private array of chars to use
var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var chars = CHARS, uuid = new Array(36), rnd = 0, r;
// RFC4122v4 compliant uuid generator
for (var i = 0; i < 36; i++) {
if (i == 8 || i == 13 || i == 18 || i == 23) {
uuid[i] = '-';
@otyeung
otyeung / send_capi_event.js
Last active May 15, 2024 07:52
Send test CAPI event in Chrome browser console window thru Data Layer variable
// Step 1 : Load Javascript library and helper function
// generate event ID using uuid function
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/uuid@8.3.2/dist/umd/uuidv4.min.js'
document.head.appendChild(script)
// load get cookie function
function getCookie(name) {
if (typeof document !== 'undefined') {
let matches = document.cookie.match(
@otyeung
otyeung / gtm_code2.js
Last active April 30, 2024 06:03
GTM code - capture li_fat_id and 1st party data (if available) - assume you have access to email, firstName, lastName, jobTitle, companyName, countryCode
/////////////////////////////////////// CAPI //////////////////////////////////////////
// read the value from LinkedIn 1st party cookie li_fat_id
function getCookie(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + "=([^;]*)"
));
// usually a cookie value is encoded, so decode it.
return matches ? decodeURIComponent(matches[1]) : undefined;
}
@otyeung
otyeung / gtm_code1.js
Last active April 1, 2024 00:50
GTM code - capture li_fat_id only by Javascript code on website
/////////////////////////////////////// CAPI //////////////////////////////////////////
// read the value from LinkedIn 1st party cookie li_fat_id
function getCookie(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + "=([^;]*)"
));
// usually a cookie value is encoded, so decode it.
return matches ? decodeURIComponent(matches[1]) : undefined;
}