# Umbraco Engage A/B Testing Custom Code Triggered Goals

**URL:** <https://forum.umbraco.com/t/umbraco-engage-a-b-testing-custom-code-triggered-goals/3467>\
**Category:** Questions\
**Tags:** v13, packages, umbraco-engage\
**Created:** [May 12, 2025, 8:35am UTC](https://forum.umbraco.com/t/umbraco-engage-a-b-testing-custom-code-triggered-goals/3467 "2025-05-12T08:35:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jboholst](https://forum.umbraco.com/user_avatar/forum.umbraco.com/jboholst/32/2058_2.png) [@jboholst](https://forum.umbraco.com/u/jboholst)\
**Post date:** [May 12, 2025, 8:35am UTC](https://forum.umbraco.com/t/umbraco-engage-a-b-testing-custom-code-triggered-goals/3467/1 "2025-05-12T08:35:33Z")

</div>

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:

```auto
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();
    }
}

```

---

<div class="post-metadata">

**Author:** ![cornehoskam](https://forum.umbraco.com/user_avatar/forum.umbraco.com/cornehoskam/32/81_2.png) [@cornehoskam](https://forum.umbraco.com/u/cornehoskam)\
**Post date:** [May 12, 2025, 9:02am UTC](https://forum.umbraco.com/t/umbraco-engage-a-b-testing-custom-code-triggered-goals/3467/2 "2025-05-12T09:02:08Z")

</div>

Hi @jboholst,

Unfortunately it is not possible to trigger a Goal without a valid pageview. By design goals can only be triggered (and are assigned to) a valid pageview. POST requests are not pageviews, only GET requests are/can be. That is there reason why you are not getting a valid pageview GUID here.

One of the ways to resolve this would be to give the Trigger method a GUID parameter, and use the pageview GUID provided by the ‘actual’ pageview (GET Request), that then makes the POST request to this API endpoint.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![jboholst](https://forum.umbraco.com/user_avatar/forum.umbraco.com/jboholst/32/2058_2.png) [@jboholst](https://forum.umbraco.com/u/jboholst)\
**Post date:** [May 12, 2025, 9:15am UTC](https://forum.umbraco.com/t/umbraco-engage-a-b-testing-custom-code-triggered-goals/3467/3 "2025-05-12T09:15:28Z")

</div>

You are a life saver @cornehoskam! Thank you very much!  
I am able to get the pageViewGuid!

```auto
@using Umbraco.Engage.Infrastructure.Analytics.Common
@inject IAnalyticsPageviewGuidManager _pageviewGuidManager;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<HomePage>
@{
    /// ... code here
    var pageId = _pageviewGuidManager.GetPageviewGuid();
    /// ... code here
}

```

---

<div class="post-metadata">

**Author:** ![system](https://forum.umbraco.com/uploads/default/original/1X/624adeddd330a3d0268a184db47946ca7e82c676.png) [@system](https://forum.umbraco.com/u/system)\
**Post date:** [June 11, 2025, 9:16am UTC](https://forum.umbraco.com/t/umbraco-engage-a-b-testing-custom-code-triggered-goals/3467/4 "2025-06-11T09:16:06Z")

</div>

Closed on June 11, 2025, 9:16am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
