Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ETH Google Analytics for AMP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
ETH Google Analytics for AMP
Merge requests
!1
WIP: Initial release
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
WIP: Initial release
develop
into
master
Overview
2
Commits
20
Changes
1
Closed
Erick Hitter
requested to merge
develop
into
master
9 years ago
Overview
2
Commits
20
Changes
1
Expand
0
0
Merge request reports
Viewing commit
e851b6d5
Prev
Next
Show latest version
1 file
+
66
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
e851b6d5
Initial pass at front-end output
· e851b6d5
Erick Hitter
authored
9 years ago
Per
https://developers.google.com/analytics/devguides/collection/amp-analytics/
eth-amp-analytics-wp.php
+
66
−
1
Options
@@ -39,13 +39,78 @@ class ETH_AMP_Analytics_WP {
return
self
::
$instance
;
}
/**
* Class properties
*/
private
$plugin_option_name
=
'eth_amp_analytics_wp'
;
private
$plugin_option_defaults
=
array
(
'property_id'
=>
null
,
);
private
$options
=
null
;
/**
* Register actions and filters
*
* @return null
*/
private
function
__construct
()
{
//
if
(
!
defined
(
'AMP__FILE__'
)
)
{
return
;
}
add_action
(
'wp_loaded'
,
array
(
$this
,
'action_wp_loaded'
)
);
}
/**
*
*/
public
function
action_wp_loaded
()
{
// Front-end
$ga_options
=
get_option
(
$this
->
plugin_option_name
);
if
(
is_array
(
$ga_options
)
)
{
$this
->
options
=
wp_parse_args
(
$ga_options
,
$this
->
plugin_option_defaults
);
add_filter
(
'amp_component_scripts'
,
array
(
$this
,
'filter_amp_component_scripts'
)
);
add_action
(
'amp_post_template_footer'
,
array
(
$this
,
'action_amp_post_template_footer'
)
);
}
}
/**
*
*/
public
function
filter_amp_component_scripts
(
$scripts
)
{
$scripts
[
'amp-analytics'
]
=
'https://cdn.ampproject.org/v0/amp-analytics-0.1.js'
;
return
$scripts
;
}
/**
*
*/
public
function
action_amp_post_template_footer
(
$amp_template
)
{
$triggers
=
array
(
'trackPageview'
=>
array
(
'on'
=>
'visible'
,
'request'
=>
'pageview'
,
),
);
$triggers
=
apply_filters
(
'eth_amp_analytics_wp_ga_triggers'
,
$triggers
,
$amp_template
);
?>
<amp-analytics
type=
"googleanalytics"
id=
"analytics1"
>
<script
type=
"application/json"
>
{
"
vars
"
:
{
"
account
"
:
"
<?php
echo
esc_js
(
$this
->
options
[
'property_id'
]
);
?>
"
},
"
triggers
"
:
<?php
wp_json_encode
(
$triggers
);
?>
}
</script>
</amp-analytics>
<?php
}
}
Loading