Giter Site home page Giter Site logo

Comments (5)

jehna avatar jehna commented on June 23, 2024

If you can add a script inside the iframe I think you could do something like:

window.ga = function() { galite.apply(galite, arguments) }

This should proxy all ga calls to galite.

I can double check when I'm on computer if that doesn't work 😄

from ga-lite.

jaskipper avatar jaskipper commented on June 23, 2024

Awesome! I'm trying to figure out how to add the script to the iFrame at the moment. I'll let you know how it turns out. That definitely works for ga calls outside of the iFrame. Thanks!

from ga-lite.

jaskipper avatar jaskipper commented on June 23, 2024

I'm having no luck with this. The code you gave me above works perfectly in the main window, but I'm unable to get it to do anything in the iFrame. The iframe is being pieced together from their 3rd party script, which is minified, but pretty printing it, this is the code that I find in the script referring to GTM. It looks like if the source is 'https://www.googletagmanager.com/gtm.js', then use that, else break. Below is that code. Any guidance would be appreciated!

ge), be = K(["\nmutation track($userId: String!, $event: String!, $properties: [String]) {\n  track(userId: $userId, event: $event, properties: $properties) {\n    status\n  }\n}\n"]), we = {
                WEBSITE_WIDGET_CLOSE: "Widget Closed",
                WEBSITE_WIDGET_OPEN: "Bubble Clicked",
                WEBSITE_WIDGET_SENT: "Conversation Started"
            }, _e = "Webchat Widget", Se = null, Ce = function e(t) {
                var n = window[window.PodiumGTMDataLayerMapping] || window.dataLayer
                  , r = fe();
                if (n) {
                    var o = {
                        event: _e,
                        eventCategory: "podium",
                        eventAction: t,
                        eventLabel: "WIDGET-TOKEN:".concat(r)
                    };
                    n.push(o)
                } else if (!Se) {
                    var i = document.getElementsByTagName("script")
                      , a = "";
                    for (var u in i) {
                        var s = i[u];
                        if (R(s.src, "https://www.googletagmanager.com/gtm.js")) {
                            a = s.src;
                            break
                        }
                    }
                    if (a) {
                        var c = new URLSearchParams(a).get("l");
                        c ? (window.PodiumGTMDataLayerMapping = c,
                        e(t)) : Se = !0
                    } else
                        Se = !0
                }
            },
          xe = function(e) {
            var t = window.ga || window[window.GoogleAnalyticsObject],
              n = t && t.getAll && t.getAll();
            t ? I(n, (function(t) {
              return t.send("event", _e, e)
            })) : t ? t("send", "event", _e, e) : O((function() {
              return window._gaq.push
            })) && window._gaq.push(["_trackEvent", _e, e])
          },
          ke = function(e) {
            window.fbq && window.fbq("trackCustom", _e, e)
          },
          Ne = function(e) {
            window.pintrk && window.pintrk("track", "custom", {
              type: _e,
              event: e
            })
          },

from ga-lite.

jehna avatar jehna commented on June 23, 2024

Hmm. Depending on if the iframe's content security policy you might be able to inject stuff to it by using something like:

var myIframe = document.getElementById('my-iframe') // or some other way to target the third-party iframe
var doc = myIframe.contentWindow.document 

// Insert ga-lite
var galiteScript = doc.createElement("script")
galiteScript.src = "https://cdn.jsdelivr.net/npm/ga-lite@2/dist/ga-lite.min.js"
doc.body.appendChild(galiteScript)

// add ga-lite proxy
var script = doc.createElement("script")
script.innerHTML = 'window.ga = function() { galite.apply(galite, arguments) }'
doc.body.appendChild(script)

from ga-lite.

jaskipper avatar jaskipper commented on June 23, 2024

I appreciate it @jehna! Will try it out this evening and let you know.

from ga-lite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.