Last active
April 22, 2022 18:47
-
-
Save alewolf/efe6883b531db5fd7c46c0477e39678b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Track ViewItem events in Facebook using the WooCommerce Pixel Manager | |
* Add this to functions.php | |
*/ | |
add_action('wp_footer', function (){ | |
?> | |
<script> | |
new Promise((resolve) => { | |
(function waitForjQuery() { | |
if (window.jQuery) return resolve() | |
setTimeout(waitForjQuery, 100) | |
})() | |
}).then(()=>{ | |
jQuery(document).on("wpmCategory", function () { | |
try { | |
if (!wpmDataLayer?.pixels?.facebook?.loaded) return | |
let eventId = wpm.getRandomEventId() | |
fbq("trackCustom", "ViewCategory", {}, { | |
eventID: eventId, | |
}) | |
jQuery(document).trigger("wpmFbCapiEvent", { | |
event_name : "ViewCategory", | |
event_id : eventId, | |
user_data : wpm.getFbUserData(), | |
event_source_url: window.location.href, | |
}) | |
} catch (e) { | |
console.error(e) | |
} | |
}) | |
}) | |
</script> | |
<?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment