Skip to content

Instantly share code, notes, and snippets.

@developit
Created May 3, 2018 22:44
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save developit/f7098c439438579cdbff4c3fd2654a47 to your computer and use it in GitHub Desktop.
Save developit/f7098c439438579cdbff4c3fd2654a47 to your computer and use it in GitHub Desktop.
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const CODE = `<script>(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','{{ID}}','auto');ga('send','pageview');</script>`;
export default class GoogleAnalyticsPlugin {
constructor ({ id }) {
this.id = id;
}
apply (compiler) {
compiler.hooks.compilation.tap('ga', compilation => {
compilation.hooks.htmlWebpackPluginAfterHtmlProcessing.tap('ga', ({ html }) => ({
html: html.replace('</body>', CODE.replace('{{ID}}', this.id) + '</body>')
}));
});
}
}
@developit
Copy link
Author

screen shot 2018-05-03 at 3 42 55 pm

@Shahramjds
Copy link

Shahramjds commented Jul 25, 2018

This project installed my app and action to native script cor

@jpzk
Copy link

jpzk commented Nov 28, 2018

What did you use to make this awesome code picture?

@williamukoh
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment