I am playing around triggering my goals through the custom code. I have tried using TriggerGoal(long goalId, int value = 0), but seems to be always getting false. I have yet to find the cause of the issue.
I opted to use the other method - TriggerGoal(Guid pageviewGuid, long goalId, int value = 0). But that would mean I need to get the pageviewGuid. Calling _pageviewGuidManager.GetPageviewGuid(); would unfortunately give me null value.
I would appreciate any input. Please see code snippet below:
public class GoalController(IGoalService _goalService,
IAnalyticsPageviewGuidManager _pageviewGuidManager,
IHttpContextAccessor _httpContextAccessor) : UmbracoApiController
{
[HttpPost]
public IActionResult Trigger()
{
HttpContext httpContext = _httpContextAccessor.HttpContext;
var pageviewGuid = _pageviewGuidManager.GetPageviewGuid();
_goalService.TriggerGoal(pageviewGuid.Value, 1, 1);
return Ok();
}
}