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
e851b6d5
Commit
e851b6d5
authored
9 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Initial pass at front-end output
Per
https://developers.google.com/analytics/devguides/collection/amp-analytics/
parent
dff69502
Branches
Branches containing commit
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
+66
-1
66 additions, 1 deletion
eth-amp-analytics-wp.php
with
66 additions
and
1 deletion
eth-amp-analytics-wp.php
+
66
−
1
View file @
e851b6d5
...
...
@@ -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
}
}
...
...
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