Skip to main content
added 1 character in body
Source Link
Chris Auer
  • 13.2k
  • 1
  • 30
  • 87

You can use the code below to add a page to the interactions collection. The pageGuid is the Item ID of the page you want to simulate.

NOTE: we are canceling the current page because I am calling all this from an API. And the API page is being tracked as a page in the interactions.

private void TrackSection(ID pageGuid)
{
    if (Tracker.Current.Session.Interaction.Pages.All(x => x.Item.Id != pageGuid.Guid))
    {
        Tracker.Current?.CurrentPage?.Cancel();
        Tracker.Current.Session.Interaction.AcceptModifications();

        var page = Tracker.Current.Session.Interaction.CreatePage();
        page.SetItemProperties(pageGuid.Guid, "en-us", 1);
        page.SetUrl(Sitecore.Context.Database.GetItem(pageGuid).Url());
    }
}

Then you can trigger the goal on the "current page" which is the page you added above.

public void TriggerGoal(ID goalId)
{
    var goalDefinition = this.goalDefinitionManager.Get(goalId.Guid, CultureInfo.InvariantCulture);
    if (goalDefinition == null)
    {
        Log.Warn($"Cannot find goal: {goalId}", this);
        return;
    }

    Log.Info($"Goal Triggered: Contact: {Tracker.Current.Contact.ContactId} : {goalId}", this);

    var page = rackerTracker.Current.CurrentPage;

    page.RegisterGoal(goalDefinition);
}

You can use the code below to add a page to the interactions collection. The pageGuid is the Item ID of the page you want to simulate.

NOTE: we are canceling the current page because I am calling all this from an API. And the API page is being tracked as a page in the interactions.

private void TrackSection(ID pageGuid)
{
    if (Tracker.Current.Session.Interaction.Pages.All(x => x.Item.Id != pageGuid.Guid))
    {
        Tracker.Current?.CurrentPage?.Cancel();
        Tracker.Current.Session.Interaction.AcceptModifications();

        var page = Tracker.Current.Session.Interaction.CreatePage();
        page.SetItemProperties(pageGuid.Guid, "en-us", 1);
        page.SetUrl(Sitecore.Context.Database.GetItem(pageGuid).Url());
    }
}

Then you can trigger the goal on the "current page" which is the page you added above.

public void TriggerGoal(ID goalId)
{
    var goalDefinition = this.goalDefinitionManager.Get(goalId.Guid, CultureInfo.InvariantCulture);
    if (goalDefinition == null)
    {
        Log.Warn($"Cannot find goal: {goalId}", this);
        return;
    }

    Log.Info($"Goal Triggered: Contact: {Tracker.Current.Contact.ContactId} : {goalId}", this);

    var page = racker.Current.CurrentPage;

    page.RegisterGoal(goalDefinition);
}

You can use the code below to add a page to the interactions collection. The pageGuid is the Item ID of the page you want to simulate.

NOTE: we are canceling the current page because I am calling all this from an API. And the API page is being tracked as a page in the interactions.

private void TrackSection(ID pageGuid)
{
    if (Tracker.Current.Session.Interaction.Pages.All(x => x.Item.Id != pageGuid.Guid))
    {
        Tracker.Current?.CurrentPage?.Cancel();
        Tracker.Current.Session.Interaction.AcceptModifications();

        var page = Tracker.Current.Session.Interaction.CreatePage();
        page.SetItemProperties(pageGuid.Guid, "en-us", 1);
        page.SetUrl(Sitecore.Context.Database.GetItem(pageGuid).Url());
    }
}

Then you can trigger the goal on the "current page" which is the page you added above.

public void TriggerGoal(ID goalId)
{
    var goalDefinition = this.goalDefinitionManager.Get(goalId.Guid, CultureInfo.InvariantCulture);
    if (goalDefinition == null)
    {
        Log.Warn($"Cannot find goal: {goalId}", this);
        return;
    }

    Log.Info($"Goal Triggered: Contact: {Tracker.Current.Contact.ContactId} : {goalId}", this);

    var page = Tracker.Current.CurrentPage;

    page.RegisterGoal(goalDefinition);
}
Source Link
Chris Auer
  • 13.2k
  • 1
  • 30
  • 87

You can use the code below to add a page to the interactions collection. The pageGuid is the Item ID of the page you want to simulate.

NOTE: we are canceling the current page because I am calling all this from an API. And the API page is being tracked as a page in the interactions.

private void TrackSection(ID pageGuid)
{
    if (Tracker.Current.Session.Interaction.Pages.All(x => x.Item.Id != pageGuid.Guid))
    {
        Tracker.Current?.CurrentPage?.Cancel();
        Tracker.Current.Session.Interaction.AcceptModifications();

        var page = Tracker.Current.Session.Interaction.CreatePage();
        page.SetItemProperties(pageGuid.Guid, "en-us", 1);
        page.SetUrl(Sitecore.Context.Database.GetItem(pageGuid).Url());
    }
}

Then you can trigger the goal on the "current page" which is the page you added above.

public void TriggerGoal(ID goalId)
{
    var goalDefinition = this.goalDefinitionManager.Get(goalId.Guid, CultureInfo.InvariantCulture);
    if (goalDefinition == null)
    {
        Log.Warn($"Cannot find goal: {goalId}", this);
        return;
    }

    Log.Info($"Goal Triggered: Contact: {Tracker.Current.Contact.ContactId} : {goalId}", this);

    var page = racker.Current.CurrentPage;

    page.RegisterGoal(goalDefinition);
}