Exemple #1
0
        /// <summary>
        /// Track a custom event.
        /// </summary>
        /// <param name="eventName">The name of the event you want to track</param>
        /// <param name="data">Any related information you’d like to attach to this event. These attributes can be used in your triggers to control who should receive the triggered email. You can set any number of data key and values.</param>
        /// <returns>Nothing if successful, throws if failed</returns>
        /// <exception cref="CustomerIoApiException">If any code besides 200 OK is returned from the server.</exception>
        public async Task TrackEventAsync(string eventName, object data = null)
        {
            var id = _customerFactory.GetCustomerId();

            var wrappedData = new TrackedEvent
            {
                Name = eventName,
                Data = data
            };

            await CallMethodAsync(MethodTrack, id, Method.POST, wrappedData);
        }
        /// <summary>
        /// Track a custom event for a non-customer.
        /// </summary>
        /// <see cref="http://customer.io/docs/invitation-emails.html" />
        /// <param name="eventName">The name of the event you want to track</param>
        /// <param name="data">Any related information you’d like to attach to this event. These attributes can be used in your triggers to control who should receive the triggered email. You can set any number of data key and values.</param>
        /// <param name="timestamp">Allows you to back-date the event, pass null to use current time</param>
        /// <returns>Nothing if successful, throws if failed</returns>
        /// <exception cref="CustomerIoApiException">If any code besides 200 OK is returned from the server.</exception>
        ///
        public async Task TrackNonCustomerEventAsync(string eventName, object data = null, DateTime?timestamp = null)
        {
            var wrappedData = new TrackedEvent
            {
                Name      = eventName,
                Data      = data,
                Timestamp = timestamp
            };

            var resource = $"{TrackEndpoint}/events";

            await CallMethodAsync(
                resource,
                HttpMethod.Post,
                wrappedData).ConfigureAwait(false);
        }
        /// <summary>
        /// Track a custom event.
        /// </summary>
        /// <param name="eventName">The name of the event you want to track</param>
        /// <param name="data">Any related information you’d like to attach to this event. These attributes can be used in your triggers to control who should receive the triggered email. You can set any number of data key and values.</param>
        /// <param name="timestamp">Allows you to back-date the event, pass null to use current time</param>
        /// <param name="customerId">Specify customer id this is valid for, or null to look it up using the customer factory.</param>
        /// <returns>Nothing if successful, throws if failed</returns>
        /// <exception cref="CustomerIoApiException">If any code besides 200 OK is returned from the server.</exception>
        public async Task TrackEventAsync(string eventName, object data = null, DateTime?timestamp = null, string customerId = null)
        {
            if (string.IsNullOrEmpty(customerId) && _customerFactory != null)
            {
                customerId = customerId ?? _customerFactory.GetCustomerId();
            }

            var wrappedData = new TrackedEvent
            {
                Name      = eventName,
                Data      = data,
                Timestamp = timestamp
            };

            var resource = $"{TrackEndpoint}/customers/{customerId}/events";

            await CallMethodAsync(
                resource,
                HttpMethod.Post,
                wrappedData).ConfigureAwait(false);
        }