We’ve migrated our documentation to a new site, which means some URLs have changed. If you hit a broken link, submit a support ticket.
Audience

GoogleユーザIDリンク

概要

Googleとの連携にでGoogleのユーザIDとCxenseユーザIDがリンク可能となり、オーディエンスセグメント、レポート作成、ターゲティングに使用することができます。

セットアップ手順

  1. アクセス中のGoogleユーザID(Googleアカウントでログインしていることが前提です)を取得します。これは一度だけ必要な手順です (詳細な情報はこちらを参照して下さい: https://developers.google.com/identity/sign-in/web/sign-in )

  2. Google IDにリンクさせるプリフィックスが必要です。既にお持ちの場合はスキップして下さい。 (詳細な情報はこちらを参照して下さい: カスタマープリフィックス )

  3. /profile/user/external/link/ updateのPersistedクエリを作成し "type"にプレフィックス設定して、 "id"と "cxid"を可変パラメータに指定します。 (詳細はPersisted クエリチュートリアルを参照してください)

  4. (オプション) Google IDは、CxenseユーザIDからGoogleユーザーを取得されないよう一方向ハッシュにすることができます。

  5. 以下のタグをページの任意の場所に追加します(ユーザーがページ遷移などを行う前に、ファイルがロードされている事を確認するのがオススメです。):

<!-- Cx Google user linking script begin -->
<script type="text/javascript">
    window.cX = window.cX || {}; cX.callQueue = cX.callQueue || [];
    cX.callQueue.push(['invoke', function() {
        var intervalId = setInterval(function() {
            if (window.gapi && gapi.auth2 && typeof gapi.auth2.getAuthInstance === 'function') {
                var auth = gapi.auth2.getAuthInstance();
                if (auth && auth.isSignedIn && typeof auth.isSignedIn.get === 'function' && auth.isSignedIn.get()) {
                    clearInterval(intervalId);

                    // Google user ID を読み込み
                    var googleUser = auth.currentUser.get();
                    var googleUserId = googleUser.getBasicProfile().getId();

                    // GoogleユーザID を CxenseユーザID にマッピングします
                    var persistedQueryId = '<PERSISTED-QUERY-ID>'; // <-- ここに PersitedクエリIDを挿入してください
                    var apiUrl = 'https://api.cxense.com/profile/user/external/link/update?callback={{callback}}'
                        + '&persisted=' + encodeURIComponent(persistedQueryId)
                        + '&json=' + encodeURIComponent(cX.JSON.stringify({ id: googleUserId, cxid: cX.getUserId() }));

                    console.log('Linking: ' + JSON.stringify({ id: googleUserId, cxid: cX.getUserId() }));
                    cX.jsonpRequest(apiUrl, function (data) { /* If wanted, verify success here*/ });
                }
            }
        }, 1000);
    }]);
    // cx.js の非同期ロード
    (function(d,s,e,t){e=d.createElement(s);e.type='text/java'+s;e.async='async';
        e.src='http'+('https:'===location.protocol?'s://s':'://')+'cdn.cxense.com/cx.js';
        t=d.getElementsByTagName(s)[0];t.parentNode.insertBefore(e,t);})(document,'script');
</script>
<!-- Cx Google user linking script end -->
 

Last updated: