Search code examples
google-analyticsexpressionengine

ExpressionEngine conditional based on Google Analytics URL tags


I am trying to create a conditional statement in ExpressionEngine that displays content based on the utm_source variable in a URL with Google Analytics campaign information.

If, for example, the url is

"www.mysite.com/landingpage/?utm_source=One" some content would be displayed

and if the url is

"www.mysite.com/landingpage/?utm_source=Two" some other content would be displayed.

To get started, I tried:

{if segment_3 == "?utm_source=One" }
    Do something special
{/if}

But ExpressionEngine does not appear to recognize the URL tag info as a 3rd segment. Any ideas as to how I might approach this?

Thanks,

-Michael


Solution

  • One I found out about today: Mo Variables

    Then your code would look like this:

    {if "{get:utm_source}" == "One"}
        Do something special
    {if:elseif "{get:utm_source}" == "Two"}
        Do something extra special
    {if:else}
        Do something boring
    {/if}
    

    There are others like this one that I've used before but just does what it says on the tin. Whereas Mo Variables does a whole lot more.