Пример #1
0
    def send_events(self, blob: blob_lib.Blob) -> blob_lib.Blob:
        """Sends all events in the blob to the GA API.

    Args:
      blob: A blob containing Google Analytics data to send.

    Returns:
      A blob containing updated data about any failing events or reports.
    """
        valid_events, invalid_indices_and_errors = (
            self._get_valid_and_invalid_events(blob.events))

        for valid_event in valid_events:
            try:
                event = valid_event[1]
                self._send_payload(event['payload'])
            except (errors.DataOutConnectorSendUnsuccessfulError,
                    errors.DataOutConnectorValueError) as error:
                index = valid_event[0]
                invalid_indices_and_errors.append((index, error.error_num))

        for invalid_event in invalid_indices_and_errors:
            event_index = invalid_event[0]
            error_num = invalid_event[1]
            blob.append_failed_event(event_index + blob.position,
                                     blob.events[event_index], error_num.value)

        return blob
Пример #2
0
    def send_events(self, blb: blob.Blob) -> blob.Blob:
        """Sends all events to Google Ads via Adwords API.

    Args:
      blb: A blob containing Customer Match data to send.

    Returns:
      A blob containing updated data about any failing events or reports.
    """
        valid_events, invalid_indices_and_errors = self._validate_events(
            blb.events)
        batches = self._batch_generator(valid_events)

        for batch in batches:
            try:
                invalid_events = self._send_batch(batch)
            except errors.DataOutConnectorAuthenticationError as error:
                for event in batch:
                    invalid_indices_and_errors.append(
                        (event[0], error.error_num))
            else:
                invalid_indices_and_errors.extend(invalid_events)

        for event in invalid_indices_and_errors:
            blb.append_failed_event(event[0] + blb.position,
                                    blb.events[event[0]], event[1].value)

        return blb
Пример #3
0
    def send_events(self, blb: blob.Blob) -> blob.Blob:
        """Sends all events in the blob to the GA API.

    Args:
      blb: A blob containing Customer Match data to send.

    Returns:
      A blob containing updated data about any failing events or reports.

    """
        valid_events, invalid_indices_and_errors = \
            self._validate_and_prepare_events_to_send(blb.events, HitTypes.EVENT)

        batches = self._batch_generator(valid_events)

        for batch in batches:
            try:
                self.send_hit(batch, send_type=SendTypes.BATCH)
            except (errors.DataOutConnectorSendUnsuccessfulError,
                    errors.DataOutConnectorValueError) as error:
                for event in batch:
                    invalid_indices_and_errors.append(
                        (event[0], error.error_num))

        for event in invalid_indices_and_errors:
            blb.append_failed_event(event[0] + blb.position,
                                    blb.events[event[0]], event[1].value)

        return blb
Пример #4
0
    def send_events(self, blb: blob.Blob) -> blob.Blob:
        """Sends Customer Match events to Google AdWords API.

    Args:
      blb: A blob containing Customer Match data to send.

    Returns:
      A blob containing updated data about any failing events or reports.

    Raises:
      DataOutConnectorValueError when user list with given name doesn't exist
      and create_list is false.
    """
        user_list_id = None
        valid_events, invalid_indices_and_errors = (
            self._validate_and_prepare_events_to_send(blb.events))
        batches = self._batch_generator(valid_events)

        for batch in batches:
            if not user_list_id:
                try:
                    user_list_id = self.get_user_list_id(self.user_list_name)
                except errors.DataOutConnectorValueError:
                    if self.create_list:
                        user_list_id = self.create_user_list(
                            self.user_list_name, self.upload_key_type,
                            self.membership_lifespan, self.app_id)
                    else:
                        raise errors.DataOutConnectorValueError(
                            'user_list_name does NOT exist (create_list = False).'
                        )
            try:
                user_list = [event[1] for event in batch]
                self.add_members_to_user_list(user_list_id, user_list)
            except errors.DataOutConnectorSendUnsuccessfulError as error:
                for event in batch:
                    invalid_indices_and_errors.append(
                        (event[0], error.error_num))

        for event in invalid_indices_and_errors:
            blb.append_failed_event(event[0] + blb.position,
                                    blb.events[event[0]], event[1].value)

        return blb
Пример #5
0
  def send_events(self, blb: blob.Blob) -> blob.Blob:
    """Sends all events to the Google Ads UAC API.

    Args:
      blb: A blob containing Customer Match data to send.

    Returns:
      A blob containing updated data about any failing events or reports.
      Reports will be formatted as a (index, EventStatus, report) tuples.
    """
    params_list = [{'params': event} for event in blb.events]
    results = async_utils.run_synchronized_function(
        self.send_conversions_to_uac, params_list)
    for i, result in enumerate(results):
      if not (isinstance(result, Dict) and result.get('response')):
        blb.append_failed_event(
            i + blb.position,
            blb.events[i],
            errors.ErrorNameIDMap.NON_RETRIABLE_ERROR_EVENT_NOT_SENT)
        blb.reports.append((i + blb.position, EventStatus.FAILURE, result))
      else:
        blb.reports.append((i + blb.position, EventStatus.SUCCESS, result))
    return blb