Commit 7ab044e1 authored by Laurent Sittler's avatar Laurent Sittler ©

Merge branch 'dev' into 'master'

Analytics scripts refactoring/optimization

See merge request SharePoint/javascript-customactions!39
parents cd9cdfb1 9f8368f7
......@@ -13,10 +13,7 @@
<pnp:ProvisioningTemplate ID="SP-MATOMO-ANALYTICS">
<pnp:CustomActions>
<pnp:SiteCustomActions>
<pnp:CustomAction Name="SPMatomoAnalytics"
Location="ScriptLink"
Sequence="0"
ScriptBlock="
<pnp:CustomAction Name="SPMatomoAnalytics" Location="ScriptLink" Sequence="0" ScriptBlock="
var headID = document.getElementsByTagName('head')[0];
var scripts = document.getElementsByTagName('script');
var scriptsSrc = [];
......@@ -28,24 +25,18 @@
}
}
if (scriptsSrc.indexOf('SPMatomoAnalytics') === -1) {
var newScript = document.createElement('script');
newScript.id = 'SPMatomoAnalytics';
newScript.type = 'text/javascript';
newScript.text = `
var _paq = window._paq || [];
{parameter:trackHeartBeatTimer}
{parameter:trackUserId}
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u='{parameter:trackingUrl}';
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{parameter:trackingSiteId}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
`;
headID.appendChild(newScript);
var _paq = window._paq || [];
{parameter:trackHeartBeatTimer}
{parameter:trackUserId}
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u='{parameter:trackingUrl}';
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{parameter:trackingSiteId}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript';g.id = 'SPMatomoAnalytics'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
scriptsSrc.push('SPMatomoAnalytics');
}" />
</pnp:SiteCustomActions>
......
......@@ -25,16 +25,10 @@
}
}
if (scriptsSrc.indexOf('SPMatomoTagManager') === -1) {
var newScript = document.createElement('script');
newScript.id = 'SPMatomoTagManager';
newScript.type = 'text/javascript';
newScript.text = `
var _mtm = _mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src='{parameter:trackingUrl}'; s.parentNode.insertBefore(g,s);
`;
headID.appendChild(newScript);
var _mtm = _mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.id = 'SPMatomoTagManager'; g.async=true; g.defer=true; g.src='{parameter:trackingUrl}'; s.parentNode.insertBefore(g,s);
scriptsSrc.push('SPMatomoTagManager');
}" />
</pnp:SiteCustomActions>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment