Skip to main content
added 1293 characters in body
Source Link
Swati Gupta
  • 3.4k
  • 1
  • 17
  • 42

I have list of items which also contains button. I am binding that list via Json . Now I want to trigger goal when some user click on that button.

  • I cannot apply goal on page because I want to trigger goal on button click

  • I tried to use sc_trk but because on click it is redirecting to some other domain, then it is also not working.

  • I tried to call web api on button click but when I am fetching goal item from DB using GetItem method, it is returning null.

Below is my code :

public static bool TriggerGoal(Sitecore.Data.ID goalId)
        {
            if (!Tracker.IsActive)
            {
                Tracker.StartTracking();
            }

            if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null)
            {
                Sitecore.Data.Items.Item goalItem = Sitecore.Context.Database.GetItem(goalId); // Getting null value
                if (goalItem != null)
                {
                    var goalTrigger = Sitecore.Analytics.Tracker.MarketingDefinitions.Goals[goalItem.ID.ToGuid()];
                    var goalEventData = Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterGoal(goalTrigger);
                    goalEventData.Data = goalItem["Name"];
                    goalEventData.ItemId = goalItem.ID.ToGuid();
                    goalEventData.DataKey = goalItem.Paths.Path;
                    goalEventData.Text = "Goal for Logic";
                    Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications();
                }
            }
            return true;
        }
 [HttpGet]
        public IHttpActionResult Get([FromUri] UrlModel model)
        {
TriggerGoal(someguid);
}

Can any one suggest me better approach?

I have list of items which also contains button. I am binding that list via Json . Now I want to trigger goal when some user click on that button.

  • I cannot apply goal on page because I want to trigger goal on button click

  • I tried to use sc_trk but because on click it is redirecting to some other domain, then it is also not working.

  • I tried to call web api on button click but when I am fetching goal item from DB using GetItem method, it is returning null.

Can any one suggest me better approach?

I have list of items which also contains button. I am binding that list via Json . Now I want to trigger goal when some user click on that button.

  • I cannot apply goal on page because I want to trigger goal on button click

  • I tried to use sc_trk but because on click it is redirecting to some other domain, then it is also not working.

  • I tried to call web api on button click but when I am fetching goal item from DB using GetItem method, it is returning null.

Below is my code :

public static bool TriggerGoal(Sitecore.Data.ID goalId)
        {
            if (!Tracker.IsActive)
            {
                Tracker.StartTracking();
            }

            if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null)
            {
                Sitecore.Data.Items.Item goalItem = Sitecore.Context.Database.GetItem(goalId); // Getting null value
                if (goalItem != null)
                {
                    var goalTrigger = Sitecore.Analytics.Tracker.MarketingDefinitions.Goals[goalItem.ID.ToGuid()];
                    var goalEventData = Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterGoal(goalTrigger);
                    goalEventData.Data = goalItem["Name"];
                    goalEventData.ItemId = goalItem.ID.ToGuid();
                    goalEventData.DataKey = goalItem.Paths.Path;
                    goalEventData.Text = "Goal for Logic";
                    Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications();
                }
            }
            return true;
        }
 [HttpGet]
        public IHttpActionResult Get([FromUri] UrlModel model)
        {
TriggerGoal(someguid);
}

Can any one suggest me better approach?

Source Link
Swati Gupta
  • 3.4k
  • 1
  • 17
  • 42

Trigger goal on dynamic item binding

I have list of items which also contains button. I am binding that list via Json . Now I want to trigger goal when some user click on that button.

  • I cannot apply goal on page because I want to trigger goal on button click

  • I tried to use sc_trk but because on click it is redirecting to some other domain, then it is also not working.

  • I tried to call web api on button click but when I am fetching goal item from DB using GetItem method, it is returning null.

Can any one suggest me better approach?