Skip to Content
Menu

utms()

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

PHP July 1, 2022

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

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 659.

    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(){
                $query_string = $this->url_components('query');
                $notable_tags = array('utm_', 'fbclid', 'mc_eid', 'gclid', 'gclsrc', 'dclid', '_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('+1 hours')); //Set/update the cookie with an hour expiration 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
                    }
                }
    
                if ( !empty($this->super->cookie['nebula_utms']) ){
                    return sanitize_text_field(htmlspecialchars($this->super->cookie['nebula_utms']));
                }
    
                return '';
            }
    

    Override

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