JSFiddle - React, Tailwind, and code Playground
by Dipak1991
JavaScript
// Check if value is undefined or null
_chkForNull = function(value) {
return value === undefined || value === null ? "" : value;
}
// Get innerText from html tag
_getInnerText = function(el) {
if (el != "") {
return el.innerText || el.textContent;
}
}
// Facebook Remarketing Pixel
_fbRemarketingPixelNew = function(pageTypes, prodIds, prodNames, prodValues) {
var eimg = document.getElementsByTagName("body")[0];
var eimgtag = document.createElement("img");
if (pageTypes == "CompleteRegistration") {
eimgtag.src = "https://www.facebook.com/tr?id=1075318492562059&ev=CompleteRegistration&noscript=1";
} else if (pageTypes != "") {
var url = "https://www.facebook.com/tr?id=1075318492562059&";
url += "ev=" + pageTypes;
url += "&cd[content_name]=" + prodNames.join(',');
url += "&cd[content_type]=product";
url += "&cd[content_ids]=" + prodIds;
url += "&cd[value]=" + prodValues.join(',');
eimgtag.src = url;
} else {
eimgtag.src = "https://www.facebook.com/tr?id=1075318492562059&ev=PageView&noscript=1";
}
eimg.appendChild(eimgtag);
}
//Get page type
_sokGetPageTypeForFBNew = function() {
var leadStep = "",htag, ptag, btag, ctag, otag, atag, stag;
htag = _chkForNull(document.getElementsByClassName("cms-index-index")[0]);
ptag = _chkForNull(document.getElementsByClassName("catalog-product-view")[0]);
btag = _chkForNull(document.getElementsByClassName("catalog-category-view")[0]);
stag = _chkForNull(_chkForNull(decodeURIComponent(window.location.href)).match(/result\/\?q/));
atag = _chkForNull(_chkForNull(decodeURIComponent(window.location.href)).match(/checkout\/cart/));
ctag = _chkForNull(_chkForNull(decodeURIComponent(window.location.href)).match(/checkout\/onepage/));
if(ptag != ""){
leadStep = "ViewContent";
} else if (otag != "" ){
leadStep = "funnel_salecomplete";
} else if (atag != "" ){
leadStep = "AddToCart";
} else if(ctag != ""){
...