본문 바로가기
개발/ALGOLIA

알고리아 Managing Results(3-10)

by dev_caleb 2022. 3. 3.
728x90

Enrich Your Records with Google Analytics Data(Google Analytics 데이터로 기록 강화)

 

https://www.algolia.com/doc/guides/managing-results/must-do/custom-ranking/how-to/enrich-your-records-with-google-analytics-data/

 

Include Google Analytics data in your records | Algolia

Learn how to add Google Analytics data to your records for a better custom ranking.

www.algolia.com

You can use data from Google Analytics to enrich your records, and boost search results based on their popularity or any other metric available in Google Analytics. This can help to improve the relevance of your search.

Because both Algolia and GA are API-based platforms, you can create scripts that update Algolia records to include any data from Google Analytics. In this guide, we’ll create a script that fetches the ga:uniquePageViews metric from Google Analytics, and add it to a pageviews attribute in our Algolia records.

 

Google Analytics의 데이터를 사용하여 레코드를 풍부하게 만들고 인기 또는 Google Analytics에서 사용할 수 있는 다른 메트릭을 기반으로 검색 결과를 높일 수 있습니다. 이렇게 하면 검색의 관련성을 향상시킬 수 있습니다.
Algolia와 Google Analytics는 모두 API 기반 플랫폼이기 때문에 Google Analytics의 데이터를 포함하도록 Algolia 레코드를 업데이트하는 스크립트를 생성할 수 있습니다. 이 가이드에서는 Google Analytics에서 ga:uniquePageViews 메트릭을 가져오는 스크립트를 만들어 Algolia 레코드의 페이지뷰 속성에 추가합니다.

 

Google Credentials

The first step is to get the credentials to use the Google Analytics API. There are multiple ways to authenticate with Google’s APIs, but in this guide we will work with service accounts. These are specifically meant for server-to-server applications.

 

첫 번째 단계는 Google Analytics API를 사용할 자격 증명을 얻는 것입니다. Google API를 인증하는 방법은 여러 가지가 있지만, 이 가이드에서는 서비스 계정으로 작업할 것입니다. 서버 간 응용 프로그램 전용입니다.

Create a service account

First, create a service account through Google API Console.

  1. Create a project (or select an existing one) from Google API Console.
  2. Activate the Analytics Reporting API in that project.
  3. In the Credentials section, create a new service account. You can skip the optional steps.
  4. Open the service account and click on Add key -> Create new key. Select JSON, and download the resulting JSON file.

먼저 구글 API 콘솔을 통해 서비스 계정을 만드세요.
1. Google API 콘솔에서 프로젝트를 생성하거나 기존 프로젝트를 선택합니다.
2. 해당 프로젝트에서 Analytics Reporting API를 활성화합니다.
3. 인증 정보 섹션에서 새 서비스 계정을 생성합니다. 선택적인 단계는 건너뛸 수 있습니다.
4. 서비스 계정을 열고 Add key -> create new key를 클릭합니다. JSON을 선택하고 결과 JSON 파일을 다운로드합니다.

 

 

Grant access to Google Analytics data(Google Analytics 데이터에 대한 액세스 권한 부여)

Now, an administrator of your Google Analytics account has to provide read access to your service account. To do this, follow these steps as an administrator:

이제 Google Analytics 계정의 관리자가 서비스 계정에 대한 읽기 액세스 권한을 제공해야 합니다. 이렇게 하려면 관리자 권한으로 다음 단계를 수행하십시오.

  1. Log in to Google Analytics.
  2. Select the account, property, and view that contain the analytics of your website.
  3. Go to the Admin tab.
  4. In the View panel (on the right side of the screen), click on View User Management.
  5. Click the + button, then click Add users.
  6. Enter the email address of the service account that was generated when creating the service account.
  7. In the Permissions panel, make sure that only the “Read & Analyze” permission is enabled.
  8. Click the Add button to confirm.

1. Google Analytics에 로그인합니다.
2. 웹 사이트의 분석이 포함된 계정, 속성 및 보기를 선택합니다.
3. 관리 탭으로 이동합니다.
4. 화면 오른쪽의 보기 패널에서 사용자 관리 보기를 클릭합니다.
5. + 단추를 클릭한 다음 사용자 추가를 클릭합니다.
6. 서비스 계정을 만들 때 생성된 서비스 계정의 이메일 주소를 입력합니다.
7. [권한] 패널에서 "읽기 및 분석" 권한만 사용 가능한지 확인합니다.
8. Add(추가) 버튼을 클릭하여 확인합니다.

 

 

Get the view ID#

To keep our script short, we’ll manually retrieve the view ID of your Google Analytics account.

  1. Return to the Admin tab of your Google Analytics View and click on View Settings.
  2. Copy the View ID number. You have to put this in the GA_PARAMETERS object of the script later on.

view ID# 가져오기

스크립트를 짧게 유지하기 위해 Google Analytics 계정의 보기 ID를 수동으로 검색합니다.
1. Google Analytics 보기의 관리 탭으로 돌아가서 설정 보기를 클릭합니다.
2. ID 보기 번호를 복사합니다. 나중에 스크립트의 GA_PARAMATERS 개체에 입력해야 합니다.

 

 

 

 

Prepare your records 레코드 준비

The only constraint for this guide, is that your records must have an attribute that contains the full URL of their associated page. By default, our script expects the url attribute to hold this, but you can change that if needed.


이 안내서의 유일한 제약 사항은 레코드에 연결된 페이지의 전체 URL을 포함하는 속성이 있어야 한다는 것입니다. 기본적으로 스크립트에서는 url 속성이 이 값을 보유할 것으로 예상하지만 필요한 경우 변경할 수 있습니다.

Create the script

Now that we have our credentials and our records ready, we can create a script to fetch the Google Analytics data of our view and inject them into our existing records. For that, we use:

스크립트 만들기

이제 자격 증명과 레코드가 준비되었으므로 스크립트로 Google Analytics 데이터를 가져와 기존 레코드에 삽입할 수 있습니다. 이를 위해 다음을 사용합니다.
-구글 API 클라이언트
-알골리아 API 클라이언트

Fetch Google Analytics data(Google 분석 데이터 가져오기)

To fetch the Google Analytics (GA) data of our view, we will use the Google API endpoint batchGetmethod. In our script, we specify the following parameters for this method:

Google Analytics(GA) 데이터를 가져오기 위해 Google API 엔드포인트 batchGetmethod를 사용합니다. 스크립트에서는 이 방법에 대해 다음 매개 변수를 지정합니다.

  • The viewId.
  • The dateRanges to specify the period we want to fetch the data for.
  • The dimensions: we need the ga:hostname and ga:pagePath to rebuild full URL of the page.
  • The metrics that you want to use in your custom ranking strategy. You can choose any metrics from the complete list of available metrics.
  • orderBys: In our example, we order the pages by uniquePageViews.
  • pageSize and pageToken are used for pagination. batchGet can only return a maximum of 100,000 rows. To fetch more rows, you need to use pagination.

In our example, we implement the GA data fetching in a MetricsFetcher class, which has two methods:

  • A next() method, which:
    • performs calls to batchGet,
    • keep tracks of the pagination cursor,
    • and transform the complex GA response into simple JSON objects.
  • A fetchAll() method, which:
    • iterates over the next() method, until the requested number of records are fetched,
    • and builds a big JSON object with the full URLs as keys. This will be useful in the second step of the script, where we retrieve the analytics data associated to a specific URL.

The MetricsFetcher also handles the authentication with the Service Account JSON file you’ve downloaded during the creation of your Google Service Account.

 

 

 

이거는 진짜 안쓸 것 같아서 여기까지만 하고 포스팅하지 않겠다..

728x90

'개발 > ALGOLIA' 카테고리의 다른 글

알고리아 Managing Results(3-12)  (0) 2022.03.03
알고리아 Managing Results(3-11)  (0) 2022.03.03
알고리아 Managing Results(3-9)  (0) 2022.03.03
알고리아 Managing Results(3-8)  (0) 2022.03.03
알고리아 Managing Results(3-7)  (0) 2022.03.03