2

All Goals trigger through programmatically are visible in the Experience Profile > Goal Report but not in Experience Analytics Report. We have triggered goal programmatically and attached with a Contact. these Goals are visible in Experience Profile but not in Experience Analytics.

Need your inputs.

Contact gExistingContact = client.Get<Contact>(new IdentifiedContactReference(_identifier, userKey),
                           new ContactExpandOptions(PersonalInformation.DefaultFacetKey));

                    if (gExistingContact != null)
                    {
                        Guid glID = Guid.Parse(goalId.ToString());
                        var goalItem = Sitecore.Context.Database.GetItem(goalId);

                        var xconnectEvent = new Goal(glID, DateTime.UtcNow);

                        xconnectEvent.CustomValues.Add("Action", action);
                        xconnectEvent.CustomValues.Add("PageName", pageName);
                        xconnectEvent.CustomValues.Add("Date", DateTime.Now.ToString());

                        if (goalItem != null)
                        {
                            if (goalItem["Points"] != null && !string.IsNullOrEmpty(goalItem["Points"].ToString()))
                            {
                                xconnectEvent.EngagementValue = goalItem["Points"] == null ? 0 : int.Parse(goalItem["Points"].ToString());
                            }
                        }

                        Guid channelId = Guid.Parse(channelid.ToString());
                        var useragent = "Mozilla / 5.0(iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit / 602.1.50(KHTML, like Gecko) CriOS / 56.0.2924.75 Mobile / 14E5239e Safari/ 602.1";
                        Interaction interaction = new Sitecore.XConnect.Interaction(gExistingContact, InteractionInitiator.Contact, channelId, useragent);
                        interaction.Events.Add(xconnectEvent);
                        client.AddInteraction(interaction);
                        client.Submit();
                    }
  • 1
    You issue is that your interaction is not a page/web interaction. It is an xConnect interaction. And by default Sitecore does not include non-web based interactions into Experience Analytics. In Himmat Singh Dulawat answer below, that is a web interaction Tracker.Current.CurrentPage.RegisterGoal. You can change you goal to a web interaction or let me find you the setting to include the non-web interaction in EA. – Chris Auer Jun 23 at 18:19
2

If your interaction doesn`t have WebVisit it is invisible in Experience Analytics by default. You can change you goal to a web interaction as @Chris Auer mentioned or remove(patch)

<InteractionFilter type="Sitecore.ExperienceAnalytics.Aggregation.Filters.WebVisitFilter, Sitecore.ExperienceAnalytics.Aggregation" />

from Sitecore.ExperienceAnalytics.Aggregation.config for corresponding dimensions to make interactions without WebVisit visible in EA.

If you need web visit for your interaction but you don`t have Tracker.Current in your API context you can modify your code to add "fake" web visit:

//Add Device profile
DeviceProfile newDeviceProfile = new DeviceProfile(Guid.NewGuid()) { LastKnownContact = gExistingContact };
client.AddDeviceProfile(newDeviceProfile);
interaction.DeviceProfile = newDeviceProfile;

//Add fake Ip info
IpInfo fakeIpInfo = new IpInfo("127.0.0.1") { BusinessName = "Home"};
client.SetFacet(interaction, IpInfo.DefaultFacetKey, fakeIpInfo);

// Add fake webvisit
// Create a new web visit facet model
var webVisitFacet = new WebVisit
{
    Browser =
        new BrowserData
        {
            BrowserMajorName = "Chrome",
            BrowserMinorName = "Desktop",
            BrowserVersion = "22.0"
        },
    Language = "en",
    OperatingSystem =
        new OperatingSystemData { Name = "Windows", MajorVersion = "10", MinorVersion = "4" },
    Referrer = "https://www.google.com",
    Screen = new ScreenData { ScreenHeight = 1080, ScreenWidth = 685 },
    SearchKeywords = "sitecore",
    SiteName = "website"
};

// Populate data about the web visit
// Home page itemId
var itemId = Guid.Parse("110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9");
var itemVersion = 1;

// First page view
PageViewEvent pageView = new PageViewEvent(DateTime.Now,
    itemId, itemVersion, "en")
{
    ItemLanguage = "en",
    Duration = new TimeSpan(3000),
    Url = "/home"
};

interaction.Events.Add(pageView);
client.SetWebVisit(interaction, webVisitFacet);
1

Update your code as below, it works for me and I am able to see Goal in Experience Profile and in Experience Analytics Report as well.

if (!Tracker.IsActive)
        {
            Tracker.StartTracking();
        }
        if (Tracker.IsActive && Tracker.Current.CurrentPage != null)
        {
            Sitecore.Data.Items.Item goalItem = Sitecore.Context.Database.GetItem(goalId);
            if (goalItem != null)
            {
                var goalTrigger = Tracker.MarketingDefinitions.Goals[goalId.ToGuid()];
                var goalEventData = Tracker.Current.CurrentPage.RegisterGoal(goalTrigger);
                goalEventData.Data = goalItem["Name"];
                goalEventData.ItemId = goalItem.ID.ToGuid();
                goalEventData.DataKey = goalItem.Paths.Path;
                goalEventData.Text = goalItem["Name"];
                Tracker.Current.Interaction.AcceptModifications();
            }
        }

Here goalId is Guid Type of created goal in the marketing control panel. You can find more details about How to create a goal and deploy here.

  • I am triggering the Goal through external API. We are using FXM in our project. In that case the above code will work? – Dipak Sanki Jun 24 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.