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
Commits
ba7e6be4
Commit
ba7e6be4
authored
9 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Update to use assistance the plugin provides
See
https://github.com/Automattic/amp-wp/pull/247
parent
e0d85b58
No related branches found
No related tags found
1 merge request
!1
WIP: Initial release
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eth-amp-analytics-wp.php
+20
-30
20 additions, 30 deletions
eth-amp-analytics-wp.php
with
20 additions
and
30 deletions
eth-amp-analytics-wp.php
+
20
−
30
View file @
ba7e6be4
...
...
@@ -97,8 +97,7 @@ class ETH_AMP_Analytics_WP {
*/
public
function
action_wp_loaded
()
{
if
(
!
empty
(
$this
->
get_option
(
'property_id'
)
)
)
{
add_filter
(
'amp_post_template_data'
,
array
(
$this
,
'filter_amp_post_template_data'
)
);
add_action
(
'amp_post_template_footer'
,
array
(
$this
,
'action_amp_post_template_footer'
)
);
add_filter
(
'amp_post_template_analytics'
,
array
(
$this
,
'filter_amp_post_template_analytics'
)
);
}
}
...
...
@@ -107,41 +106,32 @@ class ETH_AMP_Analytics_WP {
*/
/**
* Include component script
*
* Must appear before AMP JS library, per https://developers.google.com/analytics/devguides/collection/amp-analytics/
* Set analytics properties
*/
public
function
filter_amp_post_template_
data
(
$data
)
{
if
(
!
is
set
(
$data
[
'amp_component_scripts'
][
'amp-
analytics
'
]
)
)
{
$
data
[
'amp_component_scripts'
][
'amp-
analytics
'
]
=
'https://cdn.ampproject.org/v0/amp-analytics-0.1.js'
;
public
function
filter_amp_post_template_
analytics
(
$analytics
)
{
if
(
!
is
_array
(
$
analytics
)
)
{
$analytics
=
array
()
;
}
return
$data
;
}
/**
* Add GA settings to post body
*/
public
function
action_amp_post_template_footer
(
$amp_template
)
{
$output
=
array
(
'vars'
=>
array
(
'account'
=>
$this
->
get_option
(
'property_id'
),
$analytics
[
'eth-amp-googleanalytics'
]
=
array
(
'type'
=>
'googleanalytics'
,
'attributes'
=>
array
(
// 'data-credentials' => 'include',
),
'triggers'
=>
array
(
'trackPageview'
=>
array
(
'on'
=>
'visible'
,
'request'
=>
'pageview'
,
'config_data'
=>
array
(
'vars'
=>
array
(
'account'
=>
$this
->
get_option
(
'property_id'
),
),
'triggers'
=>
array
(
'trackPageview'
=>
array
(
'on'
=>
'visible'
,
'request'
=>
'pageview'
,
),
),
),
);
$output
=
apply_filters
(
'eth_amp_analytics_wp_ga_settings_js'
,
$output
);
?>
<amp-analytics
type=
"googleanalytics"
id=
"analytics1"
>
<script
type=
"application/json"
>
<?php
echo
wp_json_encode
(
$output
);
?>
</script>
</amp-analytics>
<?php
return
$analytics
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment