using System;
#if UNITY_ANDROID
using UnityEngine;
#endif
namespace JustTrack
{
///
/// A representation of the attribution returned by the server.
///
public class AttributionResponse
{
///
/// Initializes a new instance of the class.
///
/// The attribution campaign.
/// The user type.
/// The attribution type.
/// The attribution channel.
/// The attribution partner.
/// The source ID.
/// The source bundle ID.
/// The source placement.
/// The ad set ID.
/// The creation date and time.
private AttributionResponse(AttributionCampaign pCampaign, string pUserType, string pType, AttributionChannel pChannel, AttributionPartner pPartner, string? pSourceId, string? pSourceBundleId, string? pSourcePlacement, string? pAdsetId, DateTime pCreatedAt)
{
this.Campaign = pCampaign;
this.UserType = pUserType;
this.Type = pType;
this.Channel = pChannel;
this.Partner = pPartner;
this.SourceId = pSourceId;
this.SourceBundleId = pSourceBundleId;
this.SourcePlacement = pSourcePlacement;
this.AdsetId = pAdsetId;
this.CreatedAt = pCreatedAt;
}
///
/// Gets the attribution campaign.
///
public AttributionCampaign Campaign { get; private set; }
///
/// Gets the user type for this attribution.
///
public string UserType { get; private set; }
///
/// Gets the attribution type.
///
public string Type { get; private set; }
///
/// Gets the attribution channel.
///
public AttributionChannel Channel { get; private set; }
///
/// Gets the attribution partner.
///
public AttributionPartner Partner { get; private set; }
///
/// Gets the source ID for this attribution.
///
public string? SourceId { get; private set; }
///
/// Gets the source bundle ID for this attribution.
///
public string? SourceBundleId { get; private set; }
///
/// Gets the source placement for this attribution.
///
public string? SourcePlacement { get; private set; }
///
/// Gets the ad set ID for this attribution.
///
public string? AdsetId { get; private set; }
///
/// Gets the creation date and time of this attribution.
///
public DateTime CreatedAt { get; private set; }
#if UNITY_ANDROID
internal static AttributionResponse FromAndroidObject(AndroidJavaObject pResponseObject) {
using var campaign = pResponseObject.Call("getCampaign");
using var channel = pResponseObject.Call("getChannel");
using var partner = pResponseObject.Call("getPartner");
using var createdAt = pResponseObject.Call("getCreatedAt");
return new AttributionResponse(
AttributionCampaign.FromAndroidObject(campaign),
pResponseObject.Call("getUserType"),
pResponseObject.Call("getType"),
AttributionChannel.FromAndroidObject(channel),
AttributionPartner.FromAndroidObject(partner),
pResponseObject.Call("getSourceId"),
pResponseObject.Call("getSourceBundleId"),
pResponseObject.Call("getSourcePlacement"),
pResponseObject.Call("getAdsetId"),
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + new TimeSpan(createdAt.Call("getTime") * 10000)
);
}
#endif
#if UNITY_IOS || UNITY_WEBGL
internal static AttributionResponse CreateResponse(string userType, string type, int campaignId, string campaignName, string campaignType, int channelId, string channelName, bool channelIncent, int partnerId, string partnerName, string? sourceId, string? sourceBundleId, string? sourcePlacement, string? adsetId, DateTime createdAt) {
return new AttributionResponse(
AttributionCampaign.CreateCampaign(campaignId, campaignName, campaignType),
userType,
type,
AttributionChannel.CreateChannel(channelId, channelName, channelIncent),
AttributionPartner.CreatePartner(partnerId, partnerName),
sourceId,
sourceBundleId,
sourcePlacement,
adsetId,
createdAt
);
}
#endif
#if UNITY_EDITOR
internal static AttributionResponse CreateFakeResponse() {
return new AttributionResponse(
AttributionCampaign.CreateFakeCampaign(1, "fake campaign", "acquisition"),
"acquisition",
"fake",
AttributionChannel.CreateFakeChannel(1, "Direct", false),
AttributionPartner.CreateFakePartner(1, "Organic"),
"fake source id",
"fake source bundle id",
"fake source placemenet",
"fake adset id",
DateTime.UtcNow
);
}
#endif
}
}