npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gitbook-plugin-google-tongji-with-multiple-channel

v0.1.0

Published

GitBook plugin that use Google Analytics to analyze website traffic, support for independent analysis of multiple channels, a source code deployed in multiple independent analysis.

Downloads

10

Readme

Welcome to gitbook-plugin-google-tongji-with-multiple-channel 👋

npm:version npm:download npm:prerequisite github:documentation github:maintenance npm:license github:snodreams1006 website:snodreams1006.tech 微信公众号:雪之梦技术驿站-brightgreen.svg

GitBook plugin that use Google Analytics to analyze website traffic, support for independent analysis of multiple channels, a source code deployed in multiple independent analysis.

🏠 Homepage

Preview

Usage

{
    "plugins": [
        "google-tongji-with-multiple-channel"
    ],
    "pluginsConfig": {
        "google-tongji-with-multiple-channel": {
            "token": "UA-140787039-1"
        }
    }
}

Result

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-140787039-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-140787039-1');
</script>

Usage

Step #1 - Update book.json file

In you gitbook's book.json file, add google-tongji-with-multiple-channel to plugins list.

Here is simplest example :

{
    "plugins": [
        "google-tongji-with-multiple-channel"
    ],
    "pluginsConfig": {
        "google-tongji-with-multiple-channel": {
            "token": "UA-XXXX-Y"
        }
    }
}

In addition, the supported configuration options are as follows :

"gitbook": {
    "properties": {
        "token": {
            "description": "Google Analytics token",
            "required": false,
            "type": "string"
        },
        "url": {
            "description": "Google Analytics Url",
            "default": "https://www.googletagmanager.com/gtag/js",
            "required": false,
            "type": "string"
        },
        "multipleChannelConfig": {
            "description": "Google Analytics Multi-channel Configuration",
            "required": false,
            "type": "object"
        }
    }
}

Step #2 - Run gitbook commands

  • Run gitbook install. It will automatically install google-tongji-with-multiple-channel gitbook plugin for your book. This is needed only once.
gitbook install

or you can run npm install gitbook-plugin-google-tongji-with-multiple-channel to install locally.

npm install gitbook-plugin-google-tongji-with-multiple-channel
  • Build your book (gitbook build) or serve (gitbook serve) as usual.
gitbook serve

Step #3 - Verify that Google analysis code is injected

After uploading to the website, visit the homepage of the website to check whether the Google analysis script file is automatically injected.

You can also check whether the configuration is successfully configured in the Google analysis background.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-140787039-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-140787039-1');
</script>

Apply

Step #1- Sign up for Google analytics

Visit the Google analysis website, register or log in the Google analysis account, click create media resources and fill in the relevant information of the website.

|name|demo|remark| |:-:|:-:|:-:| |name|github|required| |website|https://snowdreams1006.github.io/|required| |categories|other|required| |timezone|GMT+08:00|optional|

Step #2- Get the Google analysis code

After adding media resources successfully, click next to get the integration code script as follows:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-140787039-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-140787039-1');
</script>

|name|demo|remark| |:-:|:-:|:-:| |Source address|https://www.googletagmanager.com/gtag/js?id=UA-140787039-1|async| |url|https://www.googletagmanager.com/gtag/js|Each site has the same value| |token|UA-140787039-1|Each site has a google-tongji-with-multiple-channelerent value|

Step #3- Fill in the Google analysis configuration

Copy the token and url just applied and fill in the book.json configuration file, and fill in the Google analysis configuration information according to the actual situation.

  • Single channel configuration only needs to fill in the value of token, the rest of the options are optional.
"google-tongji-with-multiple-channel": {
  "token": "UA-140787039-1"
}
  • In addition to filling in the value of token corresponding to the website domain name, multiple channels also need to fill in the Google analysis url
"google-tongji-with-multiple-channel": {
    "url": "https://www.googletagmanager.com/gtag/js",
    "multipleChannelConfig": {
         "snowdreams1006.gitbook.io":{
            "token": "UA-140787039-1"
        },
        "snowdreams1006.github.io":{
            "token": "UA-140787039-2"
        },
        "snowdreams1006.gitee.io":{
            "token": "UA-140787039-3"
        },
        "snowdreams1006.gitlab.io":{
            "token": "UA-140787039-4"
        },
        "snowdreams1006.tech":{
            "token": "UA-140787039-5"
        },
        "blog.snowdreams1006.cn":{
            "token": "UA-140787039-6"
        }
    }
}

Examples

  • Official documentation configuration file

https://github.com/snowdreams1006/gitbook-plugin-google-tongji-with-multiple-channel/blob/master/docs/book.json

{
    "plugins": ["google-tongji-with-multiple-channel"],
    "pluginsConfig": {
        "google-tongji-with-multiple-channel": {
            "multipleChannelConfig": {
                 "snowdreams1006.gitbook.io":{
                    "token": "UA-140787039-1"
                },
                "snowdreams1006.github.io":{
                    "token": "UA-140787039-2"
                },
                "snowdreams1006.gitee.io":{
                    "token": "UA-140787039-3"
                },
                "snowdreams1006.gitlab.io":{
                    "token": "UA-140787039-4"
                },
                "snowdreams1006.tech":{
                    "token": "UA-140787039-5"
                },
                "blog.snowdreams1006.cn":{
                    "token": "UA-140787039-6"
                }
            }
        }
    }
}
  • Official example configuration file

https://github.com/snowdreams1006/gitbook-plugin-google-tongji-with-multiple-channel/blob/master/example/book.json

{
    "plugins": ["google-tongji-with-multiple-channel"],
    "pluginsConfig": {
        "google-tongji-with-multiple-channel": {
            "token": "UA-140787039-1"
        }
    }
}

Note: Above snippet can be used as complete book.json file, if your book doesn't have one yet.

Thanks

Author

👤 snowdreams1006

Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.

Show your support

Give a Star if this project helped you!

Copyright

Copyright © 2019 snowdreams1006.

This project is MIT licensed.