1

I am trying to get the campaign values from the URL parameters, for tracking in Magento, inside a controller action.

I am using \Magento\Framework\App\RequestInterface->getParam('utm_source') and it returns empty value, or getParams() and checking the param array, 'utm_source' is missing.

This happens if the URL is like this: https://example.com/frontName/controllerName/actionName/?utm_source=test

If the URL is: https://example.com/frontName/controllerName/actionName/utm_source/test

or like this: https://example.com/frontName/controllerName/actionName/?utm%5Fsource=test

then 'utm_source' is present in the params array.

I am trying Magento\Framework\UrlInterface->getCurrentUrl() and the utm_ query params are missing from the url. If I have multiple params, both utm_ and non utm_ like this:

https://example.com/frontName/controllerName/actionName/?utm_source=test&test=value&utm_campaign=testcampaign then getCurrentUrl() returns https://example.com/frontName/controllerName/actionName/?test=value

I have searched for utm_ everywhere inside the vendor folder, the only place I have found is in module-page-cache/etc/varnish4/5/6.vcl, which is excluding utm_ from caching.

So, how does one get the param?

1
  • I have also faced this issue. Do not remember the exact solution but I use one of these. First solution is try to get it using $_GET and second solution is parse the url.
    – Abbas
    Commented Dec 16, 2021 at 1:05

4 Answers 4

2

Ok, since somebody else might have the same issue.

I have opened a support ticket with Adobe, this is the response that I've got: enter image description here

Followed the instructions and now everything is working as expected.

But, basically, you can exclude some parameters from a link, so that you can cache that page. Because, a lot of times, you have google or other platforms adding unique parameters to your URL, so that the campaign can be tracked. But, the page is the same, even if the params are the different. So for example you can have example.com/?utm_source=facebook and example.com/?utm_source=google. To avoid caching each page separately, you can ignore this utm_source param at all.

0

If your controller extended \Magento\Framework\App\Action\Action then using

using $this->getRequest()->getParams(); you get all Get and Post params values.

For getting for a single get param use $this->getRequest()->getParam({paramName});. Example: $this->getRequest()->getParam('utm_medium').

0

Requirement = From URL such as http://base-url/test/index/utm?utm_source=154&utm_medium=medium&utm_content=casonsad

You want to get utm_source, utm_medium, and utm_content values using the Magento controller.

Solution is

namespace Abbas\Test\Controller\Index;

class Utm extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        var_dump($_GET);
    }
}
namespace Abbas\Test\Controller\Index;

class Utm extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        var_dump($_GET);
    }
}

enter image description here

1
  • Do not use $_GET or $_POST, instead use the requestInterface. Do not extend the action class, instead, implement the post or get interface
    – Dan
    Commented Feb 16, 2022 at 22:58
0

I have tried the same on my PC, which has nothin to do with work environment, and it works fine, I do get the parameter. When trying it in our work adobe commerce cloud environment, or even a clean Magento instance on my work machine, then the issue is present, so, I guess it has something to do with our network or something else. Will raise this with our management. Thanks

2
  • Hey did you get a solution for your problem. I am also facing the same issue, can you guide me? Commented Feb 15, 2022 at 8:05
  • Check marked accepted response, I have added it in there
    – Dan
    Commented Feb 16, 2022 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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