• Resolved leflores

    (@leflores)


    Hi,

    We added the AMP plugin to my site, and try to setup AMP analytics.

    We use a custom analytic solution, and need to send site variables to our analytics.

    How could we parse site values into analytics data?

    Ex:

    {
                "requests": {
                    "pageview": "https://myanalytics.com/event?page_author=${article_authors}"
                    },
                "vars": {
                   "article_author": "This is the author" # SEND AUTHOR NAME!!!!!!!!
                },
             
                "triggers": {
                    "trackPageview": {
                        "on": "visible",
                        "request": "pageview"
                    }
                    
                },
                "transport": {
                    "beacon": false,
                    "xhrpost": false,
                    "image": true
                }
            }

    Tried to use <?php echo get_the_author_firstname(); ?> but it not work.

    Is there a way to do this using the analytics section?

    Thanks

    • This topic was modified 3 years, 11 months ago by leflores.
    • This topic was modified 3 years, 11 months ago by leflores.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @leflores

    Thank you for contacting us, If you are using a highly customized solution, We will recommend creating a custom endpoint and using that as a config, the response would be configuration json.

    eg:
    <amp-analytics config="https://example.com/analytics.config.json"></amp-analytics>

    If you wanted to pass one or two values, you can use the amp_analytics_entries filter to search and replace them.

    eg:

    add_filter(
    	'amp_analytics_entries',
    	function ( $analytics_entries ) {
    
    		$author_name = ( ! empty( get_the_author_meta( 'first_name' ) ) ) ? get_the_author_meta( 'first_name' ) : get_the_author_meta( 'display_name' );
    
    		if ( empty( $analytics_entries ) || empty( $author_name ) ) {
    			return $analytics_entries;
    		}
    		
    		foreach ( $analytics_entries as &$analytics_entry ) {
    			if ( isset( $analytics_entry['type'] ) && 'yourcustomtype' === $analytics_entry['type'] ) {
    				$analytics_entry['config'] = str_replace( '/%author%/', $author_name, $analytics_entry['config'] );
    			}
    		}
    		return $analytics_entries;
    	}
    );

    Hope this helps!

    • This reply was modified 3 years, 11 months ago by Milind More.
    Plugin Support Milind More

    (@milindmore22)

    @leflores
    We hope our suggestion is helpful, I’ll mark this as resolved Open a new support topic if you face further issues, also feel free to leave a plugin review, we would love to hear your feedback.

    Plugin Support Milind More

    (@milindmore22)

    @leflores

    I just realized that I forgot to mention JSON config changes. you need to add %author% in where you want your author name.

    {
    	"requests": {
    		"pageview": "https://myanalytics.com/event?page_author=${article_authors}"
    	},
    	"vars": {
    		"article_author": "%author%"
    	},
    
    	"triggers": {
    		"trackPageview": {
    			"on": "visible",
    			"request": "pageview"
    		}
    
    	},
    	"transport": {
    		"beacon": false,
    		"xhrpost": false,
    		"image": true
    	}
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding site parameters to analytics json’ is closed to new replies.