-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture ga() function calls and re-route them through galite() #232
Comments
If you can add a script inside the iframe I think you could do something like:
This should proxy all I can double check when I'm on computer if that doesn't work 😄 |
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! |
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!
|
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) |
I appreciate it @jehna! Will try it out this evening and let you know. |
Thank you for all the hard work on this project. I am loving ga-lite!
I was wondering if there is a way to capture any ga() function calls (for example sending events) and route them through galite(). We've converted all of our internal ga('send', 'event'...) calls to galite('send', 'event'...), and these are working well. But we have a third party chatbot plugin installed that sends 'Bubble Clicked', 'Widget Closed' and 'Conversation Started' events to Google Analytics when using ga, but these events do not work when using ga-lite. This chatbot is inside of an iframe. Any ideas?
The text was updated successfully, but these errors were encountered: