在Gumroad overlay中添加facebook转换像素

时间:2014-09-28 02:44:36

标签: javascript facebook iframe

是否有可能在购买Gumroad重叠事件后以某种方式放置facebook转换像素? gumroad overlay是一个从Gumroad加载的脚本,允许用户在不离开页面的情况下购买产品。

一旦你到达收据页面,他们没有记录的钩子来触发事件,但我想也许可以通过篡改他们的嵌入代码来监听或触发基于iframe中发生的事情的东西?但是我知道iframe控制有限,所以不太确定。

这是他们的脚本的样子:

function receiveMessage(e) {
    if (document.getElementById(Gumroad.activeIframeId) && "0" == document.getElementById(Gumroad.activeIframeId).getAttribute("src").indexOf(e.origin)) {
        var t = e.data.split(" ")[0];
        "close" == t && Gumroad.close()
    }
}
var Gumroad = Gumroad || {
    urlBlackList: ["/signup", "/login", "/logout", "/invite", "/admin", "/settings", "/library", "/customers", "/customers_switch_product", "/imported_customers", "/purchases", "/users", "/demo", "/products", "/dashboard", "/analytics", "/balance", "/confirm", "/crossdomain", "/api", "/developers", "/api", "/partnershyp", "/films", "/ping", "/webhooks", "/revenue_share", "/jobs", "/team", "/press", "/terms", "/terms_v2", "/privacy", "/blog-posts", "/how-it-works", "/overlay", "/embed", "/modal", "/button", "/next-steps", "/charge", "/charge_data", "/CHARGE", "/examplify", "/deck", "/thank-you", "/guide", "/integrations"],
    init: function() {
        if (!(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/iPhone|iPad|iPod/i) || navigator.userAgent.match(/Opera Mini/i) || navigator.userAgent.match(/IEMobile/i)) && document.addEventListener) {
            var e = document.createElement("style"),
                t = '.gumroad-button { background-color: white !important; background-image: url(https://gumroad.com/button/button_bar.jpg) !important; background-repeat: repeat-x !important; border-radius: 4px !important; box-shadow: rgba(0, 0, 0, .4) 0 0 2px !important; color: #999 !important; display: inline-block !important; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif !important; font-size: 16px !important; font-weight: 500 !important; font-style: normal !important; line-height: 50px !important; padding: 0 15px !important; text-shadow: none !important; text-decoration: none !important; }';
            e.type = "text/css", e.styleSheet ? e.styleSheet.cssText = t : e.appendChild(document.createTextNode(t)), document.getElementsByTagName("head")[0].appendChild(e);
            for (var n = document.getElementsByClassName("gumroad-button"), r = 0; r < n.length; r++) {
                var i = n[r],
                    a = document.createElement("span");
                a.setAttribute("style", "background-image: url(https://gumroad.com/button/button_logo.png) !important; background-size: cover !important; height: 17px !important; width: 16px !important; display: inline-block !important; margin-bottom: -3px !important; margin-right: 15px !important;"), i.insertBefore(a, i.firstChild)
            }
            Gumroad.body = document.body, Gumroad.development = document.getElementById("modal-p") && "true" == document.getElementById("modal-p").getAttribute("data-gumroad-development"), Gumroad.staging = document.getElementById("modal-p") && "true" == document.getElementById("modal-p").getAttribute("data-gumroad-staging"), Gumroad.test = document.getElementById("modal-p") && "true" == document.getElementById("modal-p").getAttribute("data-gumroad-test"), Gumroad.domain = Gumroad.development ? "http://local.host:3333" : "https://gumroad.com", Gumroad.domain = Gumroad.staging ? "http://staging.gumroad.com" : Gumroad.domain, Gumroad.domain = Gumroad.test ? document.getElementById("modal-p").getAttribute("data-gumroad-testing-root-path") : Gumroad.domain, Gumroad.create('<div id="iframe_loading_indicator" style="position: fixed; z-index: 2000; color: white; top: 50%; left: 50%; margin-top: -32px; margin-left: -32px; text-align: center; height: 64px; width: 64px; background: rgba(0, 0, 0, 1); border-radius: 10px; display: none;"><img src="' + Gumroad.domain + '/overlay-loader.gif" width="32" height="32" style="position: absolute; top: 50%; margin-top: -16px; left: 50%; margin-left: -16px; width: 32px !important; height: 32px !important; padding: 0 !important;"/></div>'), Gumroad.loadingIndicatorId = "iframe_loading_indicator", Gumroad.loadingIndicator = document.getElementById(Gumroad.loadingIndicatorId), Gumroad.fadeDuration = 1e3, Gumroad.links = {};
            for (var o = document.getElementsByTagName("a"), s = Gumroad.development ? ["http://l.h:3333", "http://local.host:3333/l"] : ["http://gum.co/", "https://gum.co/", "https://gumroad.com/l/"], s = Gumroad.staging ? ["http://staging.gumroad.com/l/"] : s, s = Gumroad.test ? [Gumroad.domain + "l/"] : s, u = new RegExp(Gumroad.domain + "/[^/]+$"), l = 0; l < o.length; l++) {
                var c = o[l],
                    p = c.getAttribute("href"),
                    d = !1;
                if (void 0 != p) {
                    for (var f = 0; f < s.length; f++) 0 === p.lastIndexOf(s[f], 0) && 1 != d && (d = !0);
                    if (d) new GumroadOverlay(c, "product");
                    else if (u.test(p)) {
                        for (var h = !0, m = 0; m < Gumroad.urlBlackList.length; m++)
                            if (0 === p.lastIndexOf(Gumroad.domain + Gumroad.urlBlackList[m], 0)) {
                                h = !1;
                                break
                            }
                        h && new GumroadOverlay(c, "user")
                    }
                }
            }
        }
    },
    create: function(e) {
        var t = document.createDocumentFragment(),
            n = document.createElement("div");
        for (n.innerHTML = "hack" + e; n.firstChild;) 1 === n.firstChild.nodeType ? t.appendChild(n.firstChild) : n.removeChild(n.firstChild);
        Gumroad.body.insertBefore(t, Gumroad.body.childNodes[0])
    },
    remove: function(e) {
        return (elem = document.getElementById(e)).parentNode.removeChild(elem)
    },
    setOpacity: function(e, t) {
        return null == e ? !1 : (e.style.display = 0 == t ? "none" : "block", e.style.opacity = t, e.style.MozOpacity = t, e.style.KhtmlOpacity = t, void(e.style.filter = "alpha(opacity=" + 100 * t + ");"))
    },
    fadeOut: function(e) {
        var t = document.getElementById(e),
            n = 1,
            r = setInterval(function() {
                n -= 100 / Gumroad.fadeDuration, Gumroad.setOpacity(t, n), 0 >= n && (Gumroad.setOpacity(t, 0), t.style.display = "none", clearInterval(r))
            }, Gumroad.fadeDuration / 100)
    },
    fadeIn: function(e) {
        var t = document.getElementById(e),
            n = 0,
            r = setInterval(function() {
                n += 100 / Gumroad.fadeDuration, Gumroad.setOpacity(t, n), n >= 1 && (Gumroad.setOpacity(t, 1), clearInterval(r), t.contentWindow.focus())
            }, Gumroad.fadeDuration / 100)
    },
    newEvent: function(e, t, n, r) {
        var i = r ? function(e) {
            n.apply(r, [e])
        } : n;
        document.addEventListener ? e.addEventListener(t, i, !1) : document.attachEvent && e.attachEvent("on" + t, i)
    },
    removeEvent: function(e, t, n) {
        document.removeEventListener ? e.removeEventListener(t, n, !1) : document.detachEvent && e.detachEvent(t, n)
    },
    cancelEvent: function(e) {
        e && e.preventDefault ? e.preventDefault() : window.event.returnValue = !1
    },
    showLoadingIndicator: function() {
        Gumroad.setOpacity(Gumroad.loadingIndicator, .6)
    },
    hideLoadingIndicator: function() {
        Gumroad.loadingIndicator !== !1 && Gumroad.setOpacity(Gumroad.loadingIndicator, 0)
    },
    stopPreviews: function() {
        document.getElementById(Gumroad.activeIframeId).contentWindow.postMessage("stopPreviews", "*")
    },
    close: function(e) {
        return void 0 !== e && Gumroad.cancelEvent(e), Gumroad.activeIframeId && (Gumroad.stopPreviews(), Gumroad.fadeOut(Gumroad.activeIframeId), Gumroad.hideLoadingIndicator()), Gumroad.activeIframeId = !1, !1
    }
};
GumroadOverlay = function(e, t) {
    var n = e.getAttribute("href"),
        r = n.split("/"),
        i = n.split("#");
    this.el = e, this.id = r[r.length - 1].split("?")[0].split("#")[0], this.wanted = "", this.offerCode = "", this.locale = "", this.email = "", this.type = t, this.hash = i.length > 1 ? "#" + i[i.length - 1] : "", (6 == r.length && -1 != n.indexOf("/l/") || 5 == r.length && (-1 != n.indexOf("gum.co") || -1 != n.indexOf("l.h:"))) && (this.id = r[r.length - 2], this.offerCode = "/" + r[r.length - 1]), this.iframeId = "gumroad_" + this.type + "_" + this.id, n.split("?").length > 1 && -1 != n.split("?")[1].lastIndexOf("wanted=true") && (this.wanted = "&wanted=true"), n.split("?").length > 1 && -1 != n.split("?")[1].lastIndexOf("locale=") && (this.locale = "&locale=" + n.split("locale=")[1]), n.split("?").length > 1 && -1 != n.split("?")[1].lastIndexOf("email=") && (this.email = "&email=" + n.split("email=")[1]), Gumroad.newEvent(this.el, "click", this.show, this)
}, GumroadOverlay.prototype = {
    show: function(e) {
        if (e && Gumroad.cancelEvent(e), Gumroad.showLoadingIndicator(), null == Gumroad.links[this.iframeId]) {
            "product" == this.type ? Gumroad.create('<iframe class="gumroad_iframe" id="' + this.iframeId + '" src="' + Gumroad.domain + "/l/" + this.id + this.offerCode + "?as_modal=true" + this.wanted + this.locale + this.email + "&source_url=" + window.location.href + "&referrer=" + document.referrer + "&" + window.location.search.substring(1) + '" allowtransparency="true" style="position: fixed !important; overflow: scroll !important; z-index: 1999 !important; top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important; border: none !important; display: none; margin: 0 !important; padding: 0 !important; zoom: 1;"></iframe>') : "user" == this.type && Gumroad.create('<iframe class="gumroad_iframe" id="' + this.iframeId + '" src="' + Gumroad.domain + "/" + this.id + "?as_modal=true" + this.locale + this.email + "&source_url=" + window.location.href + "&referrer=" + document.referrer + "&" + window.location.search.substring(1) + this.hash + '" allowtransparency="true" style="position: fixed !important; overflow: scroll !important; z-index: 1999 !important; top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important; border: none !important; display: none; margin: 0 !important; padding: 0 !important; zoom: 1;"></iframe>'), Gumroad.links[this.iframeId] = !0;
            var t = document.getElementById(this.iframeId);
            Gumroad.setOpacity(t, .001), Gumroad.newEvent(t, "load", this.reallyShowIFrame, this)
        } else {
            var t = document.getElementById(this.iframeId);
            t.contentWindow.postMessage(this.hash, Gumroad.domain), this.reallyShowIFrame()
        }
        return !1
    },
    reallyShowIFrame: function() {
        Gumroad.activeIframeId = this.iframeId, Gumroad.hideLoadingIndicator(), Gumroad.fadeIn(this.iframeId)
    }
}, document.onkeydown = function() {
    27 == event.keyCode && Gumroad.close()
}, Gumroad.newEvent(window, "load", Gumroad.init), window.addEventListener ? window.addEventListener("message", receiveMessage, !1) : window.attachEvent("message", receiveMessage);

1 个答案:

答案 0 :(得分:0)

您可以在设置中将Facebook像素添加到结帐处:https://help.gumroad.com/customer/portal/articles/1579318-analytics