Skip to content

Commit 1aaf888

Browse files
committed
GA added back (#529)
1 parent ca88b88 commit 1aaf888

File tree

6 files changed

+27
-92
lines changed

6 files changed

+27
-92
lines changed

build-helpers/index-maker.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

build.js

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,18 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const ncp = require('ncp');
4-
const rimraf = require('rimraf');
5-
const less = require('less');
6-
const ng2Inline = require('./build-helpers/inliner');
7-
8-
const inline = (dir) => {
9-
let files = fs.readdirSync(dir);
10-
11-
files.forEach((file) => {
12-
const src = path.join(dir, file);
13-
14-
if (fs.statSync(src).isDirectory()) {
15-
inline(src);
16-
}
17-
else if (src.endsWith('.component.ts')) {
18-
ng2Inline(fs.readFileSync(src, 'utf-8'), {
19-
base: dir
20-
}, dir).then((file) => {
21-
fs.writeFileSync(src, file);
22-
});
23-
}
24-
});
25-
};
26-
27-
console.log('cleaning...');
28-
rimraf.sync('prebuild', fs, (err) => {
29-
if (err) {
30-
return console.error(err);
31-
}
32-
});
33-
34-
rimraf.sync('aot', fs, (err) => {
35-
if (err) {
36-
return console.error(err);
37-
}
38-
});
39-
40-
console.log('done cleaning!');
41-
42-
console.log('cloning src...');
43-
ncp('src', 'prebuild', (err) => {
44-
if (err) {
45-
return console.error(err);
46-
}
47-
48-
console.log('done cloning src!');
49-
50-
console.log('inlining...');
51-
inline(path.resolve('./prebuild/'));
52-
console.log('done inlining!');
53-
54-
console.log('ready for ngc!');
55-
});
1+
const fs = require('fs').promises;
2+
3+
async function setGa() {
4+
const html = await fs.readFile('./dist/index.html', 'utf-8');
5+
const newHtml = html.replace('<!--GA-->', `
6+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-86826463-1"></script>
7+
<script>
8+
window.dataLayer = window.dataLayer || [];
9+
function gtag(){dataLayer.push(arguments);}
10+
gtag('js', new Date());
11+
gtag('config', 'UA-86826463-1');
12+
</script>
13+
`);
14+
15+
await fs.writeFile('./dist/index.html', newHtml);
16+
}
17+
18+
setGa();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"e2e": "ng e2e --port 3200",
1414
"e2e:quick": "ng e2e --dev-server-target --webdriverUpdate=false",
1515
"e2e:headless": "HEADLESS=true ng e2e",
16-
"build:index": "cd build-helpers && node index-maker.js",
16+
"build:index": "node build.js",
1717
"build:demo": "rm -rf dist/ && ng build --prod --base-href /angular-datepicker/ && npm run build:index",
1818
"build:prod": "ng-packagr -p package.json",
1919
"release": "npm run build:prod && npm publish bin",

src/demo/demo/demo.component.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,6 @@ export class DemoComponent implements OnInit {
368368
console.log(data);
369369
}
370370

371-
trackFiver(): void {
372-
this.gaService.emitEvent('fiverr', 'clicked');
373-
}
374-
375-
toggleDisabled(disabled: boolean) {
376-
disabled ? this.formGroup.disable() : this.formGroup.enable()
377-
}
378-
379371
private buildForm(): FormGroup {
380372
return new FormGroup({
381373
datePicker: new FormControl({value: this.date, disabled: this.disabled}, [

src/demo/services/ga/ga.service.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import {Injectable} from '@angular/core';
22
import {environment} from '../../../environments/environment';
33

4-
declare const ga: Function;
4+
declare const gtag: Function;
55

66
@Injectable()
77
export class GaService {
88

99
public emitEvent(eventCategory: string,
10-
eventAction: string,
11-
eventLabel: string = null,
10+
eventLabel: string,
1211
eventValue: number = null) {
13-
if (environment.production && window['ga']) {
14-
ga('send', 'event', {
15-
eventCategory: eventCategory,
16-
eventLabel: eventLabel,
17-
eventAction: eventAction,
18-
eventValue: eventValue
12+
if (environment.production && window['gtag']) {
13+
gtag('event', 'send', {
14+
event_category: eventCategory,
15+
event_label: eventLabel,
16+
value: eventValue
1917
});
2018
}
2119
}

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
1717
</head>
1818
<body>
19-
<script id="ga-analitics"></script>
19+
<!--GA-->
2020

2121
<dp-demo-root>Loading...</dp-demo-root>
2222

0 commit comments

Comments
 (0)