GithubHelp home page GithubHelp logo

jxmked / ga4-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 10 KB

Injecting Google snippet into HTML for Analytics

Home Page: https://www.npmjs.com/package/ga4-webpack-plugin

License: MIT License

JavaScript 100.00%
ga4 gtag portfolio-include webpack-plugin

ga4-webpack-plugin's Introduction

ga4-webpack-plugin

Injecting gtag snippet into HTML for Analytics

Install

npm install ga4-webpack-plugin --save-dev

Setup

// webpack.config.js

const GA4WebpackPlugin = require('ga4-webpack-plugin');

module.exports = {
  ....

  plugins: [
    new GA4WebpackPlugin({
      // Your GTag ID. Required
      id: "GA_MEASUREMENT_ID",

      // Insert into html (true by default)
      inject: true | false,

      // Automatically call page view (true by default)
      callPageView: true | false
    })
  ]
}

Place this <ga4.analytics /> in to your index.html where to inject the gtag or else it won't inject it.

What kind of thing is about to inject?

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

  gtag("config", "GA_MEASUREMENT_ID");
</script>

but

gtag('js', new Date());
gtag('config', GA_MEASUREMENT_ID');

is optional. Set callPageView: true to insert it.

ga4-webpack-plugin's People

Contributors

jxmked avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

ga4-webpack-plugin's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.