mirror of
https://github.com/szimek/sharedrop.git
synced 2026-06-05 21:02:47 +08:00
Fix Google Analytics
This commit is contained in:
parent
298dbcbfe2
commit
bd6bbcbeae
@ -1,12 +0,0 @@
|
||||
<!-- Google Analytics -->
|
||||
<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', '{{GOOGLE_ANALYTICS_ID}}', 'auto');
|
||||
ga('send', 'pageview');
|
||||
|
||||
</script>
|
||||
<!-- End Google Analytics -->
|
||||
@ -1,22 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>ShareDrop</title>
|
||||
<meta name="description" content="ShareDrop is a peer-to-peer file sharing app powered by HTML5 WebRTC.">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta
|
||||
name="description"
|
||||
content="ShareDrop is a peer-to-peer file sharing app powered by HTML5 WebRTC."
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<link rel="shortcut icon" sizes="196x196" href="{{rootURL}}assets/images/sharedrop-icon.png">
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
sizes="196x196"
|
||||
href="{{rootURL}}assets/images/sharedrop-icon.png"
|
||||
/>
|
||||
|
||||
{{content-for "head"}}
|
||||
|
||||
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
|
||||
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/share-drop.css">
|
||||
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css" />
|
||||
<link
|
||||
integrity=""
|
||||
rel="stylesheet"
|
||||
href="{{rootURL}}assets/share-drop.css"
|
||||
/>
|
||||
|
||||
{{content-for "head-footer"}}
|
||||
{{content-for "analytics"}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@ -59,12 +59,11 @@ export function initialize(application) {
|
||||
// TODO: move it to a separate initializer
|
||||
function trackSizeOfReceivedFiles() {
|
||||
$.subscribe('file_received.p2p', (event, data) => {
|
||||
Analytics.trackEvent(
|
||||
'file',
|
||||
'received',
|
||||
'size',
|
||||
Math.round(data.info.size / 1000),
|
||||
);
|
||||
Analytics.trackEvent('received', {
|
||||
event_category: 'file',
|
||||
event_label: 'size',
|
||||
value: Math.round(data.info.size / 1000),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
export default {
|
||||
hasAnalytics() {
|
||||
return window.ga && typeof window.ga === 'function';
|
||||
},
|
||||
|
||||
trackEvent(category, action, label, value) {
|
||||
if (this.hasAnalytics()) {
|
||||
window.ga('send', 'event', category, action, label, value);
|
||||
trackEvent(name, parameters) {
|
||||
if (window.gtag && typeof window.gtag === 'function') {
|
||||
window.gtag('event', name, parameters);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@ -46,7 +46,7 @@ module.exports = function (environment) {
|
||||
}
|
||||
|
||||
if (environment === 'production') {
|
||||
ENV.GOOGLE_ANALYTICS_ID = 'UA-41889586-2';
|
||||
ENV.googleAnalyticsId = 'UA-41889586-2';
|
||||
}
|
||||
|
||||
return ENV;
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
/* eslint-env node */
|
||||
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
|
||||
|
||||
const env = process.env.EMBER_ENV;
|
||||
const config = require('./config/environment')(env);
|
||||
|
||||
module.exports = function (defaults) {
|
||||
const app = new EmberApp(defaults, {
|
||||
dotEnv: {
|
||||
@ -17,19 +14,6 @@ module.exports = function (defaults) {
|
||||
fingerprintAssetMap: true,
|
||||
},
|
||||
|
||||
inlineContent: {
|
||||
analytics: {
|
||||
file: 'app/analytics.html',
|
||||
enabled: !!config.GOOGLE_ANALYTICS_ID,
|
||||
postProcess(content) {
|
||||
return content.replace(
|
||||
/\{\{GOOGLE_ANALYTICS_ID\}\}/g,
|
||||
config.GOOGLE_ANALYTICS_ID,
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
sassOptions: {
|
||||
extension: 'sass',
|
||||
},
|
||||
|
||||
27
lib/google-analytics/index.js
Normal file
27
lib/google-analytics/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
const { name } = require('./package');
|
||||
|
||||
module.exports = {
|
||||
name,
|
||||
|
||||
isDevelopingAddon() {
|
||||
return true;
|
||||
},
|
||||
|
||||
contentFor(type, config) {
|
||||
const id = config.googleAnalyticsId;
|
||||
|
||||
if (type === 'head' && id) {
|
||||
return `
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=${id}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${id}');
|
||||
</script>
|
||||
`;
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
};
|
||||
6
lib/google-analytics/package.json
Normal file
6
lib/google-analytics/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "google-analytics",
|
||||
"keywords": [
|
||||
"ember-addon"
|
||||
]
|
||||
}
|
||||
@ -93,5 +93,10 @@
|
||||
},
|
||||
"ember": {
|
||||
"edition": "octane"
|
||||
},
|
||||
"ember-addon": {
|
||||
"paths": [
|
||||
"lib/google-analytics"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user