Wordpress integration
This script is useful for those users with a wordpress site and contains a custom set of instructions that allow to monitor your website. This script also contains the most common custom Wordpress dimensions.
Make sure to verify that your Wordpress version is at least 6.0, since it has been tested for that specific release. Make sure to enable PHP code execution.
<script>
window.publytics = window.publytics || function() { (window.publytics.q = window.publytics.q || []).push(arguments) };
<?php
if (is_single()) {
?>
publytics('pageview', {props: {
author_id: <?php echo get_the_author_meta('ID', get_post_field( 'post_author' )); ?>,
author_name: "<?php echo get_the_author_meta('nicename', get_post_field( 'post_author' )); ?>",
article_id: <?php echo get_the_ID(); ?>,
article_title: "<?php echo get_the_title(); ?>",
category_id: <?php echo get_the_category()[0]->term_id; ?>,
category_name: "<?php echo get_the_category()[0]->name; ?>",
date: "<?php echo get_the_date('Y-m-d'); ?>",
month_year: "<?php echo get_the_date('Y-m'); ?>",
year: "<?php echo get_the_date('Y'); ?>"
}});
<?php
} else {
?>
publytics('pageview');
<?php
}
?>
</script>
You must exclude our script from any caching / minification plugin (such as: WPRocket, W3Total Cache, Litespeed, etc.), otherwise these would prevent the script from working.
Wordpress AMP Script
If you use the Wordpress Plugin Ad Inserter, you can also use our script easily in the AMP pages (installed through the various available plugins). Put this code before the end of the . If you use the Wordpress Plugin AMP for WP, you can find Publytics between the tracking options available in the "Analytics" section of the plugin. You will just need to insert your tracking code #siteName/#uuid in the form field and enable the tracking.
[ADINSERTER AMP]
<?php
if (is_single()) {
?>
<amp-analytics>
<script type="application/json">
{
"requests": {
"event": "https://api.publytics.net/events"
},
"extraUrlParams": {
"r": "${documentReferrer}",
"u": "<?php echo get_the_permalink(); ?>amp/",
"w": 400,
"d": "example.com/EXMPL1"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "event",
"extraUrlParams": {
"n": "pageview",
"p": {
"amp":true,
"author_id": <?php echo get_the_author_meta('ID', get_post_field( 'post_author' )); ?>,
"author_name": "<?php echo get_the_author_meta('nicename', get_post_field( 'post_author' )); ?>",
"article_id": <?php echo get_the_ID(); ?>,
"article_title": "<?php echo get_the_title(); ?>",
"category_id": <?php echo get_the_category()[0]->term_id; ?>,
"category_name": "<?php echo get_the_category()[0]->name; ?>",
"date": "<?php echo get_the_date('Y-m-d'); ?>",
"month_year": "<?php echo get_the_date('Y-m'); ?>",
"year": "<?php echo get_the_date('Y'); ?>"
}
}
}
},
"transport": {
"beacon": true,
"xhrpost": true,
"image": false,
"useBody": true
}
}
</script>
</amp-analytics>
<?php
}
?>