Created
May 3, 2018 22:44
-
-
Save developit/f7098c439438579cdbff4c3fd2654a47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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>') | |
})); | |
}); | |
} | |
} |
Author
developit
commented
May 3, 2018
This project installed my app and action to native script cor
What did you use to make this awesome code picture?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment