Published
Edited
Jan 16, 2020
Importers
2 stars
Also listed in…
Toys
Insert cell
md`# Google Analytics In Observable
- [Google Analytics JS](https://developers.google.com/analytics/devguides/collection/analyticsjs?hl=zh-cn)

## Note
It's now only can record how many people are on your page which import this one.
`
Insert cell
md`

## How to Use
- First Get your UA code
${await FileAttachment("image@1.png").image()}

- find UA
${await FileAttachment("image@2.png").image()}

- use import {googleAnalytics} from '@yhyddr/google-analytics'
and call it
${await FileAttachment("image@3.png").image()}
${await FileAttachment("image.png").image()}
`
Insert cell
googleAnalytics('UA-132780178-6')
Insert cell
googleAnalytics = UA => {
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=${UA}';
script.type = 'text/javascript';
script.async = true;

script.onload = () => {
window.dataLayer = window.dataLayer || [];
function gtag() {
var dataLayer = window.dataLayer;
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', UA);
};
document.body.appendChild(script);
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more