I'm trying to insert the google analytics JS code into the pages downloaded by CEF client.
I decided to use CefRegisterExtension() inside of ClientApp::OnWebKitInitialized() function.
- Code: Select all
void ClientApp::OnWebKitInitialized() {
// default code here...
// my code:
std::string js_code =
"allowedDomain = 'some-domain.com';"
"currDomain = window.location.host;"
"if (currDomain === allowedDomain)"
"{"
"(function(i,s,o,g,r,a,m)"
"{i['GoogleAnalyticsObject']=r;i[r]=i[r]||function()"
"{"
"(i[r].q=i[r].q||[]).push(arguments)"
"},i[r].l=1*new Date();"
"a=s.createElement(o),"
"m=s.getElementsByTagName(o)[0];"
"a.async=1;"
"a.src=g;"
"m.parentNode.insertBefore(a,m)"
"})(window,document,'script','//www.google-analytics.com/analytics.js','ga');"
"ga('create', 'UA-12345678-1', currDomain);"
"ga('send', 'pageview');"
"}";
bool bResult = CefRegisterExtension("google_analytics_extenstion", js_code,
new ClientAppExtensionHandler(this));
}
But my application crashes every time it is trying to display the page.
If i chage the js_code to something like
- Code: Select all
std::string js_code = "alert('bla')";
Is it something wrong with my JS code? It is valid JavaScript...