-
Notifications
You must be signed in to change notification settings - Fork 383
Analytics
Weston Ruter edited this page Dec 15, 2017
·
12 revisions
To output proper analytics tags, you can use the amp_post_template_analytics filter:
add_filter( 'amp_post_template_analytics', 'xyz_amp_add_custom_analytics' );
function xyz_amp_add_custom_analytics( $analytics ) {
if ( ! is_array( $analytics ) ) {
$analytics = array();
}
// https://developers.google.com/analytics/devguides/collection/amp-analytics/
$analytics['xyz-googleanalytics'] = array(
'type' => 'googleanalytics',
'attributes' => array(
// 'data-credentials' => 'include',
),
'config_data' => array(
'vars' => array(
'account' => "UA-XXXXX-Y"
),
'triggers' => array(
'trackPageview' => array(
'on' => 'visible',
'request' => 'pageview',
),
),
),
);
// https://www.parsely.com/docs/integration/tracking/google-amp.html
$analytics['xyz-parsely'] = array(
'type' => 'parsely',
'attributes' => array(),
'config_data' => array(
'vars' => array(
'apikey' => 'YOUR APIKEY GOES HERE',
)
),
);
return $analytics;
}Each analytics entry must include a unique array key and the following attributes:
-
type:(string)one of the valid vendors for amp-analytics. -
attributes:(array)any additional valid attributes to add to theamp-analyticselement. -
config_data:(array)the config data to include in theamp-analyticsscript tag. This isjson_encode-d on output.
Notice: Please also see the plugin documentation on amp-wp.org