I need to put custom code in WordPress, but it needs the RCFX Pixel to run first. The RCFX Pixel can only run if the cookie consent has been accepted. So, my code needs to wait for the RCFX Pixel to load before running.
I added the following code to ensure that my code only runs once the cookie consent has been accepted and the RCFX Pixel is loaded.
<!-- RCFX - Primary Tracking Script -->
<script type='text/plain' data-category="analytics" data-cookieconsent="statistics" data-registered="mcfx-plugin">
/* global RCFX */
(function (w,d,o,u,a,m) {
w[o]=w[o]||function(){(w[o].q=w[o].q||[]).push(arguments);
},w[o].e=1*new Date();w[o].u=u;a=d.createElement('script'),
m=d.getElementsByTagName('script')[0];a.async=1;
a.src=u+'/mcfx.js';m.parentNode.insertBefore(a, m);
})(window, document, 'mcfx', 'https://bs.skinmds.com');
mcfx('create', 15122 );
console.log('RCFX onFormCapture ready');
mcfx(function(t) {
var formFieldMap = {
'fx-contact': ['fx-7'],
'7ab4bd82-b597-4473-acfb-feb83c4f1d13': ['0-1/message'],
'd83dc621-27c7-4795-b7f7-38800d3d3600': ['0-1/dc_referral_notes']
};
t.configure("onFormCapture", function(form) {
console.log('RCFX onFormCapture');
if (formFieldMap.hasOwnProperty(form.id)) {
var fieldsToRemove = formFieldMap[form.id];
var form_v2 = form.cloneNode(true);
form_v2.id = form.id + '_v2';
var elements = form_v2.querySelectorAll('input, select, textarea');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var name = element.getAttribute('name');
var shouldRemove = false;
for (var j = 0; j < fieldsToRemove.length; j++) {
if (fieldsToRemove[j] === name) {
shouldRemove = true;
break;
}
}
if (shouldRemove) {
element.parentNode.removeChild(element);
}
}
mcfx('capture', form_v2);
console.log('RCFX capture success');
}
});
});
</script>
Custom code is added with Cookie Consent for WordPress.