Skip to content

Instantly share code, notes, and snippets.

@dvygolov
Created May 14, 2024 15:36
Show Gist options
  • Save dvygolov/238298c6e21d19ae3d56f9a461767205 to your computer and use it in GitHub Desktop.
Save dvygolov/238298c6e21d19ae3d56f9a461767205 to your computer and use it in GitHub Desktop.
Example of how to fire Meta Pixel event on button click
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example Page</title>
<script>
function fireMetaPixel(id, event) {
// Создание тега <img> с заданными параметрами
var img = document.createElement("img");
img.height = 1;
img.width = 1;
img.src = `https://www.facebook.com/tr?id=${id}&ev=${event}&noscript=1`;
// Вставка тега <img> сразу после <body>
document.body.insertBefore(img, document.body.firstChild);
}
</script>
</head>
<body>
<a
href="https://www.example.com"
target="_blank"
onclick="fireMetaPixel('123456', 'Lead')"
>
<button>Click me</button>
</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment