Answer
- Operation with Google Analytics 4 (hereafter GA4) has been confirmed in snf:analytics within SmartFormat. (As of 05/25/2022)
Please refer to the sample code below when writing.
Changing from existing Google Analytics to GA4
- If you are changing from your current Google Analytics (Universal Analytics, hereafter UA) to Google Analytics 4 (GA4), you need to modify the <snf:analytics> description in SmartFormat.
- If the GA4 ID is G-XXXXXXXX, and the URL of the article subject to page views is https://exsample.com/news/12345
<snf:analytics ><![CDATA[
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXX',{'page_path':'/news/12345',
'page_referrer':'http://www.smartnews.com/',
'campaign_source':'SmartNews',
'campaign_medium':'app'
});
</script>
]]>
</snf:analytics>In this case, when the article is viewed on SmartNews, the following information will be sent to the GA4 event page_view. Please modify as appropriate to match your own measurement.
page_path
/news/12345
page_referrer
http://www.smartnews.com/
source
SmartNews
medium
app
SmartFormat’s check tool will display the error "Please specify only one script tag inside item.snf:analytics," but this is not a problem.
Using existing GA (UA) and GA4 simultaneously
- If the GA4 ID is G-XXXXXXXX, the UA ID is UA-YYYYYYYY-Z, and the URL of the article subject to page views is https://exsample.com/news/12345
<snf:analytics ><![CDATA[
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXX',{
'page_path':'/news/12345',
'page_referrer':'http://www.smartnews.com/',
'campaign_source':'SmartNews',
'campaign_medium':'app'
});
gtag('config', 'UA-YYYYYYYY-Z',{
'page_path':'/news/12345',
'page_referrer':'http://www.smartnews.com/'
});
</script >
]]></snf:analytics>The same information as above is sent to GA4, and the following information is sent to UA.
Referrer / Medium
smartnews.com / referral
SmartFormat’s check tool will display the error "Please specify only one script tag inside item.snf:analytics," but this is not a problem.
Reference Information
When a link inside SmartView is tapped and the web page is transitioned to, GA4 sends the following information.
page_referrer
http://www.smartnews.com/
source
smartnews.com
medium
referral
Applicable links
- Links inside the main text
- Links for "Read on the original site"
- Links for "Recommended"
- Links on the site logo at the top of SmartView
The above measurement code is confirmed to be working as of 05/24/2022.
We do not provide measurement codes or support for measurement codes. We cannot respond to inquiries regarding specific implementation methods or measurement issues. Thank you for your understanding in advance.