Skip to Content
Menu

utms()

Easily store landing page UTM data to recall it on future pages within the session.

PHP March 21, 2023

Usage

PHP
nebula()->utms()

Parameters

This function does not accept any parameters. Is this incorrect?

Examples

Get the landing page URL and UTM parameters of a subsequent pageview

PHP
var_dump(nebula()->utms());

Get the original landing page URL and UTM parameters on a subsequent pageview in JavaScript

JavaScript
console.log(nebula.session.utms);

Read it directly from the cookie in PHP

PHP
var_dump($_COOKIE['nebula_utms']);

Read it directly from the cookie in JavaScript

JavaScript
console.log(nebula.readCookie('nebula_utms'));

Additional Notes

Important: This function requires the “Attribution Tracking” Nebula Option to be enabled in order to use it! Be sure that the use of this cookie fits within your privacy policy and other regulations.

Note that this stores the entire URL of the landing page (LP) including the entire query string if any UTM tag (or other tracking parameter) exists.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Utilities/Utilities.php on line 686.

    No Hooks

    This function does not have any filters or actions available. Request one?

    Note: This function contains 1 to-do comment.

    PHP
            public function utms(){
                if ( !$this->is_analytics_allowed() ){ //Do nothing if analytics is not allowed
                    return '';
                }
    
                if ( $this->get_option('attribution_tracking') ){ //This functionality requires the Attribution Tracking Nebula Option because it adds tracking cookies
                    //Check the cookie first
                    if ( !empty($this->super->cookie['nebula_utms']) ){
                        return sanitize_text_field(htmlspecialchars($this->super->cookie['nebula_utms']));
                    }
    
                    //Otherwise check for UTM parameters
                    $query_string = $this->url_components('query');
                    $notable_tags = array('utm_', 'fbclid', 'gclid', 'gclsrc', 'dclid', 'gbraid', 'wbraid', 'mc_eid', '_hsenc', 'vero_id', 'mkt_tok');
    
                    foreach ( $notable_tags as $tag ){
                        if ( strpos(strtolower($query_string), $tag) > -1 ){ //If UTM parameters exist //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8
                            $this->set_cookie('nebula_utms', $this->url_components('all'), strtotime('+14 months')); //Set/update the cookie and store the entire LP URL
                            return sanitize_text_field($this->url_components('all')); //Return the entire landing page URL with full query string sanitized
                        }
                    }
                }
    
                return '';
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?