Adding Google Tracking Code

CatherineKim
Topic Author
Posts: 2
5 years 6 months ago #2331 by CatherineKim
Adding Google Tracking Code was created by CatherineKim
First off, very nice Joomla extension!

I tried searching the forum, but I had no luck. I would like to add a Google event track code to each of our social media links to help with my marketing metrics. How can I do this?

Thank you!

Please Log in or Create an account to join the conversation.

Lodder
Lodder's Avatar
Posts: 1180
5 years 6 months ago - 5 years 6 months ago #2332 by Lodder
Replied by Lodder on topic Adding Google Tracking Code
Hi Catherine,

This is not a feature of the Social Slider, however you can manually add it if you wish.

I'm going to assume you have already imported the Google Analytics script on your site. If you haven't already imported it, then your template may have a setting to do so, or you can download a simple Joomla extension.

Now rather than editing the core files for the Social Slider, I'd suggest creating a Template Override . This will ensure your changes are not overridden if you install a Social Slider Update.

Once done, you will need to open the following file
templates/YOUR_TEMPLATE/html/mod_social_slider/default.php

You will firstly need to add the following code somewhere in the file, but not inside the foreach loop:
$doc = JFactory::getDocument();
$doc->addScriptDeclaration("
	var trackOutboundLink = function(url) {
		ga('send', 'event', 'outbound', 'click', url, {'hitCallback': 
			function () {
			document.location = url;
			}
		});
	}
");

Then, look for the follow code snippet
echo '<a href="' . $params->get($key . '_link') . '"' . $target . $nofollow . '>';

and replace it with this:
echo '<a href="' . $params->get($key . '_link') . '"' . $target . $nofollow . 'onclick="trackOutboundLink(\'http://www.example.com\'); return false;">';

Please note than this is for the default social icons, if you're using custom icons, then the code for this is lower down in the file.

Also, note that I have not tested the above but I can do so after the weekend if you're still a little unsure.

More information can be found on custom event tracking here:

support.google.com/analytics/answer/1136920?hl=en

I would also suggest searching the Joomla Extensions Directory as there may be some extensions there that are used for custom event tracking.

Hope this helps

Regards,
Lodder
Last edit: 5 years 6 months ago by Lodder.

Please Log in or Create an account to join the conversation.

CatherineKim
Topic Author
Posts: 2
5 years 6 months ago #2333 by CatherineKim
Replied by CatherineKim on topic Adding Google Tracking Code
Wow, great extension AND support. Thank you!

Please Log in or Create an account to join the conversation.

Lodder
Lodder's Avatar
Posts: 1180
5 years 6 months ago #2334 by Lodder
Replied by Lodder on topic Adding Google Tracking Code
You're more than welcome :)

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum