立即迁移到 Netlify

Netlify 宣布 Gatsby Cloud 的下一次迭代。 了解更多

联系我们注册
社区插件
在 GitHub 上查看插件

gatsby-plugin-plausible

npm package

一个 Gatsby 插件,用于将 Plausible 分析添加到你的 Gatsby 网站。

该插件包含 Plausible 跟踪脚本。它支持使用自定义域名以及排除特定路径来记录页面浏览量。


安装

手动

  1. 安装 gatsby-plugin-plausible

    npm install --save gatsby-plugin-plausible

  2. 将插件添加到 gatsby-config.js

    // In your gatsby-config.js
    module.exports = {
      plugins: [
        // The only required option is the domain
        {
          resolve: `gatsby-plugin-plausible`,
          options: {
            domain: `aquil.io`,
          },
        },
      ],
    };

Gatsby 配方

这将安装 gatsby-plugin-plausible 并添加一个示例配置。

  1. 将 gatsby-cli 和 gatsby 升级到最新版本

    npm install -g gatsby-cli@latest npm install gatsby@latest

  2. 运行配方 gatsby recipes https://raw.githubusercontent.com/Aquilio/gatsby-plugin-plausible/master/gatsby-recipe-plausible.mdx

  3. 更新 gatsby-config.js 选项

要了解有关配方的更多信息,请查看 公告

如何使用

注意:默认情况下,此插件仅在生产模式下运行时生成输出。要测试您的跟踪代码,请运行 gatsby build && gatsby serve.

选项

选项 说明
域名 在 Plausible 中配置的域名(必需)
customDomain 自定义域名(如果在 Plausible 的仪表板中配置)
excludePaths 不会发送页面浏览量的路径数组

页面浏览事件

当用户更改路由时,包括网站的初始加载,页面浏览量会自动发送。

触发自定义事件

要跟踪目标和转化,您必须先触发自定义事件。

window.plausible('Signup', {
  callback: () => console.info('Sent Signup event'),
});

事件名称可以是任何内容。第二个参数是一个包含选项的对象。唯一支持的选项是 callback,当事件发送后会调用它。

注意:自定义事件不会立即显示。您必须在 Plausible 仪表板中配置一个目标.

更新日志

请参阅 CHANGELOG.md

许可证

MIT © Pixelplicity

©2025Gatsby, Inc.