Using Google Analytics inside content script?
Hello everyone,
Nice to be on this forum
I'm trying to send Google Analytics events from a content file. First, I verified that the example
with-google-analytics
is working fine and GA is logging events successfully. Then I switched to the example with-content-scripts-ui
, and basically just copied over the content of popup.tsx
from the previous with-google-analytics
example into the latter example project.
I also also added the permission to my package.json:
"host_permissions": [
"https://ssl.google-analytics.com",
]
However, the events are not firing, and I'm receiving the error:
Uncaught Error: Extension context invalidated.
And the error: Uncaught (in promise) Error: Cannot find module 'fNtPQ'
This error seems to be related to trying to import google tag manager link:
import "https://www.googletagmanager.com/gtag/js?id=$PLASMO_PUBLIC_GTAG_ID"
Does it mean that remote code cannot be imported in content script context?
This link shows how to easily import remote code in a popup:
https://docs.plasmo.com/framework/remote-code
Can anyone please point me in the right direction?
If it's not possible to import remote code in content script, or background script, what is the easiest way to use google analytics in a plasmo app, without using a popup?
Thanks a lot in advance everyonePlasmo Docs
Importing Remote Code – Plasmo
Learn how to import remote code into your browser extension even in MV3.
1 Reply
Hello @sirhaveri, did you find out? Im having this same problem, my extension uses content scripts ui and don't have a popup.