Google Analytics
Updating Google Analytics for Scot's Blogger for Miva Merchant
last updated July 19, 2021
It might be necessary to do a couple minor updates to your canonical URL and Google Analytics settings to make sure your blog posts are tracked correctly.
Canonical URLs
Canonical URLs tell browsers and search engines what URL you want a page to be known by. This is useful for analytics because some posts might show up on different URls, for example, if they are in multiple categories.
If you want your blog posts to show up correctly in Google Analytics, you'll need to edit how Miva Merchant handles canonical URLs so your posts are tracked correctly.
Non Ready Theme Stores
If you have an older store that is not using a ReadyTheme, go into your main blog page and remove the following line from the template:
<link rel="canonical" href="&mvte:urls:_self:auto;" />
If you're using a ReadyTheme you may need to edit your head tag content so search engines can properly index your posts.
Go here:
MENU > USER INTERFACE > SETTINGS > HEAD TAG CONTENT
Then find the text canonical
<mvt:if expr="...">
<mvt:comment> head tag stuff </mvt:comment>
<mvt:else>
<link rel="canonical" href="https://&mvta:global:domain:name;/&mvta:page:code;.&mvt:seo_settings:suffix;" />
</mvt:if>
Just above the <mvt:else>
line, put this line in:
<mvt:elseif expr="l.settings:page:code EQ 'BLOG'">
Note: Use the code of the page you're using for your blog page. In my store the page code is BLOG so that's what I've used as an example here.
Here's what it will look like:
<mvt:elseif expr="l.settings:page:code EQ 'BLOG'">
<mvt:else>
<link rel="canonical" href="https://&mvta:global:domain:name;/&mvta:page:code;.&mvt:seo_settings:suffix;" />
</mvt:if>
Google Analytics
If you have a regular Google Analytics code block in your store, then you probably don't need to do anything else.
If you're using the analytics module that Ready Themes use your analytics template needs a minor update so your blog posts are tracked.
Go here:
MENU > Utilities > Google Analytics Tracking Code
Add this code to the top of the template:
<mvt:item name="scotsblogger" param="ga_tracking_load" />
Then replace this line:
ga( 'send', 'pageview', { 'page':'/<mvt:item name="ga_jsencode" param="ga_tracking:url_override_unencoded" />' } );
with this code (remember to change BLOG to the page code you're using):
<mvt:if expr="g.screen EQ 'BLOG'">
ga( 'send', 'pageview', { 'page':'&mvt:scotsblogger:ga_tracking;' } );
<mvt:else>
ga( 'send', 'pageview', { 'page':'/<mvt:item name="ga_jsencode" param="ga_tracking:url_override_unencoded" />' } );
</mvt:if>
so Scot's Blogger can control tracking code on blog posts while leaving everything else to Miva Merchant.
In most cases, the block of Google Analytics Tracking Code would then be (change BLOG to your page code):
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<mvt:item name="ga_jsencode" param="ga_tracking:google_id_unencoded" />', 'auto');
<mvt:if expr="g.screen EQ 'BLOG'">
ga( 'send', 'pageview', { 'page':'<mvt:item name="scotsblogger" param="ga_tracking" />' } );
<mvt:else>
ga( 'send', 'pageview', { 'page':'/<mvt:item name="ga_jsencode" param="ga_tracking:url_override_unencoded" />' } );
</mvt:if>
</script>