-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: sendHostname can works after 7 days and change GA Tracking ID #20
Changes from all commits
f3183cc
f3d11f3
e694675
af5a7ee
2d0542f
d9002a3
d5df0e8
1313b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,47 @@ | |
var object = require('./object'); | ||
var collection = require('./collection'); | ||
var type = require('./type'); | ||
var ms7days = 7 * 24 * 60 * 60 * 1000; | ||
|
||
/** | ||
* Check if the date has passed 7 days | ||
* @param {number} date - milliseconds | ||
* @returns {boolean} | ||
* @ignore | ||
*/ | ||
function isExpired(date) { | ||
var now = new Date().getTime(); | ||
|
||
return now - date > ms7days; | ||
} | ||
|
||
/** | ||
* Send hostname on DOMContentLoaded. | ||
* To prevent hostname set tui.usageStatistics to false. | ||
* @param {string} applicationId - application id to send | ||
* @param {string} appName - application name | ||
* @param {string} trackingId - GA tracking ID | ||
* @ignore | ||
*/ | ||
function sendHostname(applicationId) { | ||
function sendHostname(appName, trackingId) { | ||
var url = 'https://www.google-analytics.com/collect'; | ||
var hostname = location.hostname; | ||
var hitType = 'event'; | ||
var trackingId = 'UA-115377265-9'; | ||
var eventCategory = 'use'; | ||
var applicationKeyForStorage = 'TOAST UI ' + appName + ' for ' + hostname + ': Statistics'; | ||
var date = window.localStorage.getItem(applicationKeyForStorage); | ||
|
||
// skip only if the flag is defined and is set to false explicitly | ||
// skip if the flag is defined and is set to false explicitly | ||
if (!type.isUndefined(window.tui) && window.tui.usageStatistics === false) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if using the global There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not sure that |
||
|
||
// skip if not pass seven days old | ||
if (date && !isExpired(date)) { | ||
return; | ||
} | ||
|
||
window.localStorage.setItem(applicationKeyForStorage, new Date().getTime()); | ||
|
||
setTimeout(function() { | ||
if (document.readyState === 'interactive' || document.readyState === 'complete') { | ||
imagePing(url, { | ||
|
@@ -34,7 +57,9 @@ function sendHostname(applicationId) { | |
tid: trackingId, | ||
cid: hostname, | ||
dp: hostname, | ||
dh: applicationId | ||
dh: appName, | ||
el: appName, | ||
ec: eventCategory | ||
}); | ||
} | ||
}, 1000); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the first condition be true? This namespace
tui
always exist after loadingtui-code-snippet.js
, doesn't it?