cancel
Showing results for 
Search instead for 
Did you mean: 

Google analytics implementation on fiori launchpad

former_member338801
Participant

Hi Everyone,

Any one has implemented Google analytics tool on fiori launchpad recently?

I have followed below blog but could not connect with my requirement and generated code through GA.

Blog : https://blogs.sap.com/2017/09/09/google-analytics-for-fiori-launchpad/

Generated code :

<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXX-1'); </script>

Thanks and Regards,

RK

former_member338801
Participant
0 Kudos

Please help here if you have implement the same.

Best Regards,

RK

former_member338801
Participant
0 Kudos

This is the generated code in my case. Let me know if you have gone through similar requirement or suggested me if you would have any other approach to get usage analysis by any other way.

<!– Global site tag (gtag.js) – Google Analytics –>
< script async src=”https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-1″></script>
< script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());

gtag(‘config’, ‘UA-XXXXXX-1);
< /script>

Thanks and Regards,

RK

Accepted Solutions (0)

Answers (3)

Answers (3)

UxKjaer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi RK,

Please check the path to your files. It seems like it doesn't really know where to look. You probablt need to share your entire component.js file for me to make sense of it.

former_member338801
Participant
0 Kudos

Hi Jakob,

Please check this url :https://github.com/rkmishra2703/RK-

Let me know if you are still unable to access.

ga.png

Thanks and Regards,

RK

UxKjaer
Product and Topic Expert
Product and Topic Expert
0 Kudos

I would need to see your code to work that out.

former_member338801
Participant
0 Kudos

Thanks for your reply.

Please find below Git space to access the project. Launchpad configuration is same like mentioned in the blog except google id parameter.

z_ga_plugin.zip

https://github.com/rkmishra2703/RK-

Let me know if you need any more details.

Thanks and Regards,

RK

former_member338801
Participant
0 Kudos

Hi Jakob,

I hope you have got the required code. Let me know in case of any issue.

Auto generated code for my account is given below.

<!– Global site tag (gtag.js) – Google Analytics –>
< script async src=”[a href="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-1″>[/a]
< script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());

gtag(‘config’, ‘UA-XXXXXX-1);
< /script>

Thanks and Regards,

RK

former_member338801
Participant
0 Kudos

Hi Jakob,

Did you get a chance to look into my ask pls?

Thanks and Regards,

RK

former_member338801
Participant
0 Kudos

Hi All,

Please check if anyone has faced issue like me and help.

Thanks and Regards,

Rk

UxKjaer
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is what we use to track page changes and collect analytics. Add the following on top of your component.js in the FLP plugin

//Boostrap Google Analytics
(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', 'https://www.google-analytics.com/analytics.js', 'ga');

Add the following inside the init function

var sAppID = 'UA-XXXXXXX-' + environmentCodes[window.location.hostname.split('.')[0]];
				//Initalize the tracker
				ga('create', sAppID, 'auto');
				//Called after the plugin is loaded
				ga('send', 'pageview', {
					// 'page': location.pathname + this.cleanHash(location.hash)
					'page': this.cleanHash(location.hash)
				});
				//Called when the hash is changed
				$(window).hashchange(function () {
					ga('send', 'pageview', {
						// 'page': location.pathname + this.cleanHash(location.hash)
						'page': this.cleanHash(location.hash)
					});
				}.bind(this));


former_member338801
Participant
0 Kudos

Hi Jacob,

Really very thankful to you.

I have implemented code shared by you and added my google account Id "

'UA-XXXXXXX-'" in the code but still it is not working. I am getting below error in the console.

Error :

019-06-12 16:51:38.434020 Cannot create UI5 plugin component: (componentId/appdescrId :com.ctli.flp.ga)
Error: failed to load 'com/XX/flp/ga/Component.js' from /sap/bc/ui5_ui5/sap/z_ga_plugin/~383985DF7E1B91492FAB094D3AFB6614~5/Component.js: SyntaxError: missing ) after argument list properties {"ui5ComponentName":"com.xx.flp.ga","url":"/sap/bc/ui5_ui5/sap/z_ga_plugin/~383985DF7E1B91492FAB094D3AFB6614~5","applicationDependencies":{"url":"/sap/bc/ui5_ui5/sap/z_ga_plugin/~383985DF7E1B91492FAB094D3AFB6614~5","manifestUrl":"/sap/bc/lrep/content/~20190612111306.0878250~/apps/com.XX.flp.ga/app/sap/z_ga_plugin/manifest.appdescr","self":{"name":"com.XX.flp.ga","url":"/sap/bc/ui5_ui5/sap/z_ga_plugin/~383985DF7E1B91492FAB094D3AFB6614~5"},"asyncHints":{"libs":[{"name":"sap.m"},{"name":"sap.ui.core"},{"name":"sap.ui.unified","lazy":true}],"requests":[{"name":"sap.ui.fl.changes","reference":"com.XX.flp.ga.Component"}]},"enabled":true,"name":"com.ctli.flp.ga"}}
This indicates a plugin misconfiguration, see e.g. Note 2316443. - Error: failed to load 'com/XX/flp/ga/Component.js' from /sap/bc/ui5_ui5/sap/z_ga_plugin/~383985DF7E1B91492FAB094D3AFB6614~5/Component.js: SyntaxError: missing ) after argument list

Am I doing any mistake? Please check and let me know.

Thanks and Regards,

RK