On the 1st July 2023, Google Analytics no longer processed data for Universal Analytics at which point the only game in town is GA4, which stands for Google Analytics 4. For some products this means that part of the code needs to be rewritten to make the best use of the reporting tools that come with GA4, but for Web-D-Zine (WDZ), it just means that the code base is written to work with GA4 from the very beginning. Some of the metrics that are measured and reported are to do with the user and WDZ can not alter these, while other metrics such as links can be coded.
So when enhanced measurements is enabled the following dimensions are recorded for links
Dimension | Parameter name | Example | How this can help |
Link classes | link_classes | For < a href="https://youtu.be/FiKafunlph" class="video">, this dimension returns 'video'. | The class attribute can be repeated many times within a HTML document so can give extra information about the link, for example a class of "navigation-main-information" could refer to all of the links associated within the navigation bar for the main information |
Link domain | link_domain | For < a href="https://youtu.be/FiKafunlph">, this dimension returns 'https://youtu.be'. | If you share your content through Facebook, linked in etc. then this dimension allows you to find out which platform users use to share your content. |
Link id | link_id | For < a href="https://youtu.be/FiKafunlph" id="video-22">, this dimension returns 'video-22'. | Ids can only be used once within an html page, so it is important that the ids mean something, while still providing some information. For example with our share icons at the bottom of the page, the ids that are given are social-facebook, social-twitter, social-linkedin and social-pinterest, so if you are looking at these then you can split out all of the social clicks as well as the particular social click |
Link text | link_text | For < a href="https://youtu.be/FiKafunlph">view video< /a>, this dimension returns 'view video'. | For images this dimension is not set, however, this dimension can be useful for say comparing which textual links are more compelling |
Link url | link_url | Â For < a href="https://youtu.be/FiKafunlph">, this dimension returns 'https://youtu.be/FiKafunlph'. | Say you are publishing links to videos, then you will be able to look at which video is more popular and you can also track your videos over time |
Outbound | outbound | Â For < a href="https://youtu.be/FiKafunlph">, this dimension returns true | If a link is outbound then this parameter is set to true, while internal links are set to false |
To write code to classify links can be fairly easy for elements such as navigation bars, social icons and extra elements on a page. However, not all links come from programming. Some links like the links to Google on this page come from the editor of the page. For these links then the text can be run though a parser, which can look for all the links on a page and add appropriate information to both the class and the id.
Parser in outline
- Use preg_match_all('/]+>/i', $textToModify, $results); to find all the a links in the text to Modify
- For each of the results see if the id or class has been used. If they have not add these with useful information
- Use the results and the additional information to create a from and to array.
- When you are creating the from and to array be aware that links can be to the same location within a piece of text, so that you will have to make an allowance for this fact, so do not use the simple $modifiedText = str_replace($from, $to, $textToModify); statement as you can get repeated ids
Once all the clicks are categorised then click reports can be created to monitor all of your external links.