Rules: create

승인 필요

GTM 규칙을 만듭니다. 지금 사용해 보기 또는 예시를 확인하세요.

요청

HTTP 요청

POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules

매개변수

매개변수 이름 설명
경로 매개변수
accountId string GTM 계정 ID입니다.
containerId string GTM 컨테이너 ID입니다.

승인

이 요청을 처리하려면 다음 범위의 승인을 받아야 합니다 (인증 및 승인 자세히 알아보기).

범위
https://www.googleapis.com/auth/tagmanager.edit.containers

요청 본문

요청 본문에서는 다음과 같은 속성을 사용하여 Rules 리소스를 제공합니다.

속성 이름 설명 Notes
필수 속성
condition[].parameter[] list 조건 유형에 따라 이름이 지정된 매개변수 (키/값) 목록. 참고:
  • 바이너리 연산자의 경우 왼쪽 및 오른쪽 피연산자를 각각 지정하기 위해 arg0arg1라는 매개변수를 포함합니다.
  • 이때 왼쪽 피연산자 (arg0)는 매크로 참조여야 합니다.
  • 대소문자를 구분하지 않는 정규식 일치의 경우 true로 설정된 ignore_case이라는 부울 매개변수를 포함합니다. 지정하지 않거나 다른 값으로 설정하면 일치 항목이 대소문자를 구분합니다.
  • 연산자를 무효화하려면 negate라는 부울 매개변수를 포함하고 true로 설정합니다.
쓰기 가능
condition[].parameter[].type string 매개변수 유형. 유효한 값은 다음과 같습니다.
  • boolean: 값은 'true' 또는 'false'로 표시되는 부울을 나타냅니다.
  • integer: 이 값은 밑이 10인 64비트의 부호 있는 정수 값을 나타냅니다.
  • list: 매개변수 목록을 지정해야 함
  • map: 매개변수 맵을 지정해야 합니다.
  • template: 값은 모든 텍스트를 나타냅니다. 여기에는 매크로 참조 (문자열이 아닌 유형을 반환할 수 있는 매크로 참조도 포함)가 포함될 수 있습니다.


사용 가능한 값은 다음과 같습니다.
  • "boolean"
  • "integer"
  • "list"
  • "map"
  • "template"
쓰기 가능
condition[].type string 이 조건의 연산자 유형입니다.

사용 가능한 값은 다음과 같습니다.
  • "contains"
  • "cssSelector"
  • "endsWith"
  • "equals"
  • "greater"
  • "greaterOrEquals"
  • "less"
  • "lessOrEquals"
  • "matchRegex"
  • "startsWith"
  • "urlMatches"
쓰기 가능
name string 규칙 표시 이름입니다. 쓰기 가능
선택적 속성
condition[] list 이 규칙을 구성하는 조건의 목록 (규칙 간 암시적 AND) 쓰기 가능
condition[].parameter[].key string 매개변수를 고유하게 식별하는 이름이 지정된 키입니다. 최상위 수준 매개변수 및 지도 값에 필요합니다. 목록 값의 경우 무시됩니다. 쓰기 가능
condition[].parameter[].list[] list 이 목록 매개변수의 매개변수입니다 (키는 무시됨). 쓰기 가능
condition[].parameter[].map[] list 이 매핑 매개변수의 매개변수입니다 (키가 있어야 함, 키는 고유해야 함). 쓰기 가능
condition[].parameter[].value string 지정된 유형에 적합한 매개변수의 값('"와 같은 매크로 참조를 포함할 수 있음) 쓰기 가능
notes string 사용자가 컨테이너에서 이 규칙을 적용하는 방법에 대한 메모 쓰기 가능

응답

요청에 성공할 경우 이 메서드는 응답 본문에 Rules 리소스를 반환합니다.

참고: 이 메서드에 제공되는 코드 예시가 지원되는 모든 프로그래밍 언어를 나타내는 것은 아닙니다. 지원되는 언어 목록은 클라이언트 라이브러리 페이지를 참조하세요.

Java

자바 클라이언트 라이브러리를 사용합니다.

/*
 * Note: This code assumes you have an authorized tagmanager service object.
 */

/*
 * This request creates a new rule for the authorized user.
 */

// Construct the condition parameters.
Parameter arg0 = new Parameter();
arg0.setType("template");
arg0.setKey("arg0");
arg0.setValue("{{url}}");

Parameter arg1 = new Parameter();
arg1.setType("template");
arg1.setKey("arg1");
arg1.setValue(".*hellowworld.html");

// Construct the condition object
Condition condition = new Condition();
condition.setType("endsWith");
condition.setParameter(Arrays.asList(arg0, arg1));

// Construct the rule object.
Rule rule = new Rule();
rule.setName("Ends With Rule");
rule.setCondition(Arrays.asList(condition));

try {
  Rule response = tagmanager.accounts().
      containers().rules().create("123456", "54321", rule).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * The results of the create method are stored in the response object.
 * The following code shows how to access the created Id and Fingerprint.
 */
System.out.println("Rule Id = " + response.getRuleId());
System.out.println("Rule Fingerprint = " + response.getFingerprint());

Python

Python 클라이언트 라이브러리를 사용합니다.

# Note: This code assumes you have an authorized tagmanager service object.

# This request creates a new rule for the authorized user.
try:
  response = tagmanager.accounts().containers().rules().create(
      accountId='123456',
      containerId='54321',
      body={
          'name': 'Ends with Rule',
          'condition': [
              {
                  'type': 'endsWith',
                  'parameter': [
                      {
                          'type': 'template',
                          'key': 'arg0',
                          'value': '{{url}}'
                      },
                      {
                          'type': 'template',
                          'key': 'arg1',
                          'value': '.*hellowworld.html'
                      }
                  ]
              }
          ]
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

# The results of the create method are stored in the response object.
# The following code shows how to access the created id and fingerprint.
print 'Rule Id = %s' % response.get('ruleId')
print 'Rule Fingerprint = %s' % response.get('fingerprint')

사용해 보기

아래의 API 탐색기를 사용하여 실시간 데이터를 대상으로 이 메소드를 호출하고 응답을 확인해 보세요.