-
Notifications
You must be signed in to change notification settings - Fork 18
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
Retrieve DataLayer from Chrome extension scope #39
Comments
It's a little bit of a mess because of the different permissions / APIs that various scripts get access to, the basic data flow is:
|
Well, that's a whole lot to do just to gain access to a dataLayer ... |
Anyways, thank you for your kind and detailed answer. I will do my best to mirror these effects in a lesser scale. Thanks! |
Yeah, unfortunately it is the result of the sandboxing and the various APIs. If you're building an extension that doesn't add a DevTools panel it will be a bit easier as you won't have to worry about the last step-- but I haven't found any other way to gain access to variables in the page scope other than injecting a script tag. Best of luck! |
To be clear, I am aiming to watch the dataLayer content for a chrome extension which purpose is only limited to one use. We aim at pitching a recommendation tool based on ecommerce data for a website and will use the extension to create a demo on a real session. I would gladly take any shortpath you have to just retrieve a GTM dataLayer object the dirty way, just so I get the data inside it. Thanks anyways... ! |
Based on that use case it sounds like you may be able to get away with only using a content script and the injected script-- I would review the code for those in dataslayer and see what you can create based on them. The injected script probably won't have to be modified at all unless you want to remove support for non-GTM data layer objects. The actions taken on datalayer objects are in the following lines of the content script: https://github.com/sean-adams/dataslayer/blob/master/src/content.js#L20-L38 |
It seems the Error for the head is
it says line 9 because I have scrapped away the first if statement and the |
This is getting a little bit beyond the scope of this issue so I will have to leave you on your own shortly 😄 but make sure your extension manifest declares the appropriate permissions and web_accessible_resources-- see https://github.com/sean-adams/dataslayer/blob/master/src/manifest.json |
Also you will probably need to keep oo_poly, this is a shim for Object.observe support which was removed from Chrome but we are still using to monitor the dataLayer. |
Okay, problem solved: adding the Thanks again for such a precious help. |
De rien 😄 |
HI There - @sean-adams @Spriithy , I'm facing exactly the same problem... unable to access the dataLayer from my chrome extension. (I simply want to access and loop through the data). The links above are broken though... was wondering if you came up with a solution? Thank you! |
Hey there, I was wondering how you managed to extract the dataLayer content from the tab given the fact that the JS runtime of the chrome extension is sandboxed and therefore doesn't share states with the page ?
Thanks in advance
The text was updated successfully, but these errors were encountered: