支持的框架 Supported frameworks
- Electron:通过
rev-utils辅助库提供官方支持(见下文) Electron, with first-class support through therev-utilshelper - Tauri
- NW.js、CEF、Wails、Neutralino 等基于 Chromium 或 webview 的框架 NW.js, CEF, Wails, Neutralino and other Chromium- or webview-based frameworks
- 内嵌 webview 的原生应用:WebView2(Windows)、WKWebView(macOS)、WebKitGTK(Linux) Native apps with an embedded webview: WebView2 (Windows), WKWebView (macOS) and WebKitGTK (Linux)
桌面要求 Desktop requirements
- 在用户的默认浏览器中打开广告点击。 用户点击广告时,请在默认浏览器中打开落地页,而不是在应用窗口内跳转。仅在用户真实点击时打开链接;拦截非用户触发的跳转和弹窗,以及由广告发起的文件下载。 Open ad clicks in the user’s default browser. When someone clicks an ad, open the landing page in their default browser rather than navigating your app’s window. Only open links in response to a real click. Block navigations and popups the user didn’t trigger, and block file downloads started by ads.
- 发送标准的浏览器 User Agent。 许多框架会在 User Agent 字符串中加入框架名称和应用名称(例如
Electron/…或MyApp/…)。请移除这些部分,使其与普通浏览器一致。非标准的 User Agent 可能被判定为无效流量(IVT)。 Send a standard browser User Agent. Many frameworks add their own name, and your app’s name, to the User Agent string (for exampleElectron/…orMyApp/…). Remove those parts so the string looks like a regular browser. Non-standard User Agents may be flagged as IVT (invalid traffic).
Electron
rev-utils 会为您处理这两项要求。
rev-utils handles both requirements for you.
安装 Installation
安装rev-utils库,为您的 Electron 应用添加完整的广告支持。我们可能会不定期更新该包。 Install the rev-utils library to augment your Electron setup with full compatibility for ads. We may occasionally update the package.使用方法 Usage
使用new BrowserWindow创建新窗口后,将窗口对象和electron全局变量传入 setupRevUtils。
After creating a window with new BrowserWindow, pass the window and the
electron global into setupRevUtils.
main.js
setupRevUtils在底层调用了窗口的两个函数:
-setupLinkHandler:用于打开广告(同时拦截恶意行为!)
-setUserAgent:用于移除User Agent字符串中的非标准部分,这些非标准内容可能触发无效流量(IVT)检测。
Under the hood, setupRevUtils calls two functions on the window -
setupLinkHandler to open ads (and block malicious behavior!) -
setUserAgent, which removes non-standard portions of the User Agent string
which may trigger IVT (invalid traffic).Tauri
在您的域名上建立一个包含 RevIQ 脚本和广告位的页面(参见Frontend),然后在一个发送标准 User Agent、并在用户浏览器中打开广告点击的子 webview 中显示它。 Build a page on your domain with the RevIQ script and your ad slots (see Frontend), then show it in a child webview that sends a standard User Agent and opens ad clicks in the user’s browser.src-tauri/src/ads.rs
Window::add_child 属于 Tauri 的 unstable 功能。请在 src-tauri/Cargo.toml 的 tauri 中启用:tauri = { version = "2", features = ["unstable"] }。
Window::add_child is behind Tauri’s unstable feature. Enable it on tauri
in src-tauri/Cargo.toml: tauri = { version = "2", features = ["unstable"] }.src-tauri/src/ads-init.js
src-tauri/src/main.rs
ads webview 所需的这一个命令:
Because the ad page is loaded from your domain (remote content), Tauri blocks it from calling commands unless a capability opts that origin in. Grant the ads webview only the one command it needs:
src-tauri/capabilities/ads.json
src-tauri/permissions/open-ad-link.toml
其他框架 Other frameworks
使用您所用框架自身的 API 满足这两项要求:为 webview 设置标准的浏览器 User Agent,并且仅在用户真实点击后,将广告框架中的链接点击和window.open 调用在系统浏览器中打开。完整方案请参见上面的 Tauri 示例。
Meet the two requirements with your framework’s own APIs: set a standard
browser User Agent on the webview, and send link clicks and window.open calls
from ad frames to the system browser, only right after a real click. The Tauri
example above shows the full pattern.
使用的框架未在此列出?只要它能渲染 Web 内容即可正常工作。如需设置方面的帮助,请联系您的 RevIQ 客户经理。
Building with a framework not listed here? It will work as long as it renders
web content. Contact your RevIQ account manager if you need help with setup.