Запрос в Google Tag Manager - PullRequest
0 голосов
/ 27 января 2020

Я застрял в проблеме использования менеджера тегов Google из node.js.

Проблема заключается в следующем: -

Создайте пользовательский триггер, тип которого «Просмотр страницы», и он запускается Некоторые просмотры страниц (конкретный URL).

Я использую API диспетчера тегов Google в node.js, но это не сработало. Он также не работает в API менеджера тегов Goggle, API, упомянутый в документе менеджера тегов Google: «https://developers.google.com/tag-manager/api/v2/reference/accounts/containers/workspaces/triggers/create»

Request-

parent- account / 4702174396 / Containers / 13436436 / Рабочие пространства / 1 полезная нагрузка-

{
  "name": "test1",
  "type": "pageview",
  "filter": [
    {
      "parameter": [
        {
          "type": "template",
          "value": "https://mail.google.com/mail/u/0/?tab=rm&ogbl#inbox",
          "key": "link"
        }
      ],
      "type": "equals"
    }
  ],
  "autoEventFilter": [],
  "customEventFilter": [],
  "checkValidation": {
    "type": "boolean",
    "value": "false"
  },
  "waitForTags": {
    "type": "boolean",
    "value": "false"
  }
}

error-

{
  "error": {
    "code": 400,
    "message": "Unable to parse trigger data",
    "errors": [
      {
        "message": "Unable to parse trigger data",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

И мой node.js код указан ниже:

const { google } = require('googleapis');
const tagmanager = google.tagmanager('v2');

async function getAuthClient() {
    const auth = await google.auth.getClient({
        // Scopes can be specified either as an array or as a single, space-delimited string.
        scopes: [
            'https://www.googleapis.com/auth/tagmanager.edit.containers',
            'https://www.googleapis.com/auth/tagmanager.manage.accounts',
            'https://www.googleapis.com/auth/tagmanager.readonly',
            'https://www.googleapis.com/auth/tagmanager.delete.containers',
            'https://www.googleapis.com/auth/tagmanager.manage.users',
            'https://www.googleapis.com/auth/tagmanager.publish',
            'https://www.googleapis.com/auth/tagmanager.edit.containerversions'
        ]
    });

    // obtain the current project Id
    const project = await google.auth.getProjectId();

    console.log('project====================>', project);
    console.log('auth=======================>', auth);
    global.auth = auth;
}
getAuthClient().catch(console.error);

async function createTrigger(containerId) {
    try {
        const response = await tagmanager.accounts.containers.workspaces.triggers.create({
            'parent': accounts/4702174396/containers/13436436/workspaces/1,
            auth,
            'resource': {
                "name": "test1",
                "type": "pageview",
                "filter": [
                    {
                        "type": "equals",
                        "parameter": [
                            {
                                "type": "template",
                                "value": "https://mail.google.com/mail/u/0/?tab=rm&ogbl#inbox",
                                "key": "link"
                            }
                        ]
                    }
                ]
            },
            "customEventFilter": [

            ],
            "autoEventFilter": [

            ],
            "checkValidation": {
                "type": "boolean",
                "value": "false"
            },
            "waitForTags": {
                "type": "boolean",
                "value": "false"
            }
        });
        console.log('createTrigger==================>', response);
        return response.data;
    } catch (error) {
        console.log('createTrigger==================>', error);
        throw error;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...