質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google Analytics

Google AnalyticsはGoogleが開発した無料のウェブ分析のソリューションです。複数のクライアント側のAPIとデータをエクスポートし管理するREST APIも格納されています。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google Analytics API

Google Analytics APIは、アクセス解析機能が行える API(Application Programming Interface)です。

Q&A

解決済

1回答

357閲覧

Google AnalyticsのEmbed api エラー

masateru2

総合スコア39

Google Analytics

Google AnalyticsはGoogleが開発した無料のウェブ分析のソリューションです。複数のクライアント側のAPIとデータをエクスポートし管理するREST APIも格納されています。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google Analytics API

Google Analytics APIは、アクセス解析機能が行える API(Application Programming Interface)です。

0グッド

0クリップ

投稿2018/07/18 08:03

編集2018/07/18 08:16

https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started
公式のサンプルコードをそのままコピペしてHTMLを起動してみたら、下記のエラーがコンソールログで吐かれました

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

書いたソースコードは公式のコピペなのですが、こちらです。

html

1<!DOCTYPE html> 2<html> 3<head> 4 <title>Embed API Demo</title> 5</head> 6<body> 7 8<!-- Step 1: Create the containing elements. --> 9 10<section id="auth-button"></section> 11<section id="view-selector"></section> 12<section id="timeline"></section> 13 14<!-- Step 2: Load the library. --> 15 16<script> 17(function(w,d,s,g,js,fjs){ 18 g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}}; 19 js=d.createElement(s);fjs=d.getElementsByTagName(s)[0]; 20 js.src='https://apis.google.com/js/platform.js'; 21 fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')}; 22}(window,document,'script')); 23</script> 24 25<script> 26gapi.analytics.ready(function() { 27 28 // Step 3: Authorize the user. 29 30 var CLIENT_ID = '自分のクライアントID(OAuth2.0)'; 31 32 gapi.analytics.auth.authorize({ 33 container: 'auth-button', 34 clientid: CLIENT_ID, 35 }); 36 37 // Step 4: Create the view selector. 38 39 var viewSelector = new gapi.analytics.ViewSelector({ 40 container: 'view-selector' 41 }); 42 43 // Step 5: Create the timeline chart. 44 45 var timeline = new gapi.analytics.googleCharts.DataChart({ 46 reportType: 'ga', 47 query: { 48 'dimensions': 'ga:date', 49 'metrics': 'ga:sessions', 50 'start-date': '30daysAgo', 51 'end-date': 'yesterday', 52 }, 53 chart: { 54 type: 'LINE', 55 container: 'timeline' 56 } 57 }); 58 59 // Step 6: Hook up the components to work together. 60 61 gapi.analytics.auth.on('success', function(response) { 62 viewSelector.execute(); 63 }); 64 65 viewSelector.on('change', function(ids) { 66 var newIds = { 67 query: { 68 ids: ids 69 } 70 } 71 timeline.set(newIds).execute(); 72 }); 73}); 74</script> 75</body> 76</html> 77

ちなみに色々試していたところ上記のコンソールログはjs.src部分をコメントアウトすると消えます。

html

1<script> 2(function(w,d,s,g,js,fjs){ 3 g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}}; 4 js=d.createElement(s);fjs=d.getElementsByTagName(s)[0]; 5 //js.src='https://apis.google.com/js/platform.js'; 6 fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')}; 7}(window,document,'script')); 8</script> 9

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

単純にユーザー認証が行われていなかった

投稿2018/08/09 07:57

masateru2

総合スコア39

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問