Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
586 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
305 changes: 304 additions & 1 deletion
305
analytics-hook/docroot/META-INF/custom_jsps/html/js/analytics/analytics.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
177 changes: 92 additions & 85 deletions
177
...ocroot/META-INF/custom_jsps/html/js/analytics/integrations/liferay-analytics-processor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,119 @@ | ||
;(function() { | ||
var ioRequest; | ||
var isFunction; | ||
var pendingFlush; | ||
var requestId; | ||
var requestInterval; | ||
var requestUri; | ||
var themeDisplayData = {}; | ||
|
||
var LiferayAnalyticsProcessor = Liferay.Analytics.integration('LiferayAnalyticsProcessor').readyOnInitialize(); | ||
|
||
LiferayAnalyticsProcessor.prototype._ready = true; | ||
|
||
LiferayAnalyticsProcessor.prototype.flush = function(callback) { | ||
var instance = this; | ||
|
||
var events = instance.getPendingEvents(); | ||
|
||
pendingFlush = false; | ||
|
||
if (events.length) { | ||
if (ioRequest) { | ||
ioRequest( | ||
requestUri, | ||
{ | ||
data: { | ||
events: JSON.stringify(events), | ||
themeDisplayData: JSON.stringify(themeDisplayData) | ||
}, | ||
on: { | ||
failure: function(err) { | ||
console.error(err.type); | ||
}, | ||
success: function() { | ||
if (isFunction(callback)) { | ||
callback(); | ||
AUI().use( | ||
'json', | ||
function(A) { | ||
var ioRequest; | ||
var isFunction; | ||
var pendingFlush; | ||
var requestId; | ||
var requestInterval; | ||
var requestUri; | ||
var themeDisplayData = {}; | ||
|
||
var LiferayAnalyticsProcessor = Liferay.Analytics.integration('LiferayAnalyticsProcessor').readyOnInitialize(); | ||
|
||
LiferayAnalyticsProcessor.prototype._ready = true; | ||
|
||
LiferayAnalyticsProcessor.prototype.flush = function (callback) { | ||
var instance = this; | ||
|
||
var events = instance.getPendingEvents(); | ||
|
||
pendingFlush = false; | ||
|
||
if (events.length) { | ||
if (ioRequest) { | ||
ioRequest( | ||
requestUri, | ||
{ | ||
data: { | ||
events: A.JSON.stringify(events), | ||
themeDisplayData: A.JSON.stringify(themeDisplayData) | ||
}, | ||
on: { | ||
failure: function (err) { | ||
console.error(err.type); | ||
}, | ||
success: function () { | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
instance.store([]); | ||
|
||
requestId = clearInterval(requestId); | ||
} | ||
); | ||
else { | ||
pendingFlush = true; | ||
} | ||
} | ||
}; | ||
|
||
instance.store([]); | ||
LiferayAnalyticsProcessor.prototype.getPendingEvents = function () { | ||
var instance = this; | ||
|
||
requestId = clearInterval(requestId); | ||
} | ||
else { | ||
pendingFlush = true; | ||
} | ||
} | ||
}; | ||
var storedEvents = localStorage.getItem('ct-analytics-events') || '[]'; | ||
|
||
LiferayAnalyticsProcessor.prototype.getPendingEvents = function() { | ||
var instance = this; | ||
return A.JSON.parse(storedEvents); | ||
}; | ||
|
||
var storedEvents = localStorage.getItem('ct-analytics-events') || '[]'; | ||
LiferayAnalyticsProcessor.prototype.initialize = function () { | ||
var instance = this; | ||
|
||
return JSON.parse(storedEvents); | ||
}; | ||
requestInterval = instance.options.interval; | ||
requestUri = instance.options.uri; | ||
|
||
LiferayAnalyticsProcessor.prototype.initialize = function() { | ||
var instance = this; | ||
AUI().use( | ||
'aui-io-request', | ||
function (A) { | ||
A.Object.each( | ||
themeDisplay, | ||
function (item, index) { | ||
if (A.Lang.isFunction(item)) { | ||
var indexName = /^(get|is)(.*)$/.exec(index)[2]; | ||
|
||
requestInterval = instance.options.interval; | ||
requestUri = instance.options.uri; | ||
var indexNameFirstCharacter = indexName.charAt(0); | ||
|
||
AUI().use( | ||
'aui-io-request', | ||
function(A) { | ||
A.Object.each( | ||
themeDisplay, | ||
function(item, index) { | ||
if (A.Lang.isFunction(item)) { | ||
var indexName = /^(get|is)(.*)$/.exec(index)[2]; | ||
indexName = indexNameFirstCharacter.toLowerCase() + indexName.slice(1); | ||
|
||
indexName = indexName[0].toLowerCase() + indexName.slice(1); | ||
themeDisplayData[indexName] = themeDisplay[index](); | ||
} | ||
} | ||
); | ||
|
||
themeDisplayData[indexName] = themeDisplay[index](); | ||
} | ||
isFunction = A.Lang.isFunction; | ||
ioRequest = A.io.request; | ||
} | ||
); | ||
}; | ||
|
||
isFunction = A.Lang.isFunction; | ||
ioRequest = A.io.request; | ||
} | ||
); | ||
}; | ||
LiferayAnalyticsProcessor.prototype.store = function (events) { | ||
var instance = this; | ||
|
||
LiferayAnalyticsProcessor.prototype.store = function(events) { | ||
var instance = this; | ||
events = events || []; | ||
|
||
events = events || []; | ||
localStorage.setItem('ct-analytics-events', A.JSON.stringify(events)); | ||
}; | ||
|
||
localStorage.setItem('ct-analytics-events', JSON.stringify(events)); | ||
}; | ||
LiferayAnalyticsProcessor.prototype.track = function (event, properties) { | ||
var instance = this; | ||
|
||
LiferayAnalyticsProcessor.prototype.track = function(event, properties) { | ||
var instance = this; | ||
var events = instance.getPendingEvents(); | ||
|
||
var events = instance.getPendingEvents(); | ||
events.push(event.obj); | ||
|
||
events.push(event.obj); | ||
instance.store(events); | ||
|
||
instance.store(events); | ||
if (!requestId) { | ||
requestId = setTimeout(instance.flush.bind(instance), requestInterval); | ||
} | ||
}; | ||
|
||
if (!requestId) { | ||
requestId = setTimeout(instance.flush.bind(instance), requestInterval); | ||
Liferay.Analytics.addIntegration(LiferayAnalyticsProcessor); | ||
} | ||
}; | ||
|
||
Liferay.Analytics.addIntegration(LiferayAnalyticsProcessor); | ||
); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
|
||
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"> | ||
<portlet> | ||
<portlet-name>anonymous-users-api</portlet-name> | ||
<portlet-class>com.liferay.portal.kernel.portlet.LiferayPortlet</portlet-class> | ||
<supports> | ||
<mime-type>text/html</mime-type> | ||
</supports> | ||
<portlet-info> | ||
<title>Anonymous Users Service</title> | ||
<short-title>Anonymous Users Service</short-title> | ||
<keywords>Anonymous Users Service</keywords> | ||
</portlet-info> | ||
</portlet> | ||
</portlet-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.