blob: a16a12cca89471987e28ec9f7d62522ed1ab1d9e [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/lib/analytics/cpp/google_analytics/event.h"
namespace {
constexpr char kHitTypeKey[] = "t";
constexpr char kHitType[] = "event";
constexpr char kCategoryKey[] = "ec";
constexpr char kActionKey[] = "ea";
constexpr char kLabelKey[] = "el";
constexpr char kValueKey[] = "ev";
} // namespace
namespace analytics::google_analytics {
Event::Event(std::string_view category, std::string_view action,
const std::optional<std::string_view>& label, const std::optional<int64_t>& value) {
parameters_[kHitTypeKey] = kHitType;
parameters_[kCategoryKey] = category;
parameters_[kActionKey] = action;
if (label.has_value())
parameters_[kLabelKey] = label.value();
if (value.has_value())
parameters_[kValueKey] = std::to_string(value.value());
}
void Event::AddGeneralParameters(const GeneralParameters& general_parameters) {
const auto& parameters = general_parameters.parameters();
parameters_.insert(parameters.begin(), parameters.end());
}
} // namespace analytics::google_analytics