Skip to content

Commit

Permalink
unique anonId and adblock request
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed May 18, 2020
1 parent ca8cd92 commit 9e33e85
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
14 changes: 10 additions & 4 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Analytics {
this.storage.setUserId(this.userId);
this.deviceId = this.getDeviceId();
this.eventRepository = EventRepository;
this.sendAdblockPage = false
this.readyCallback = () => {};
this.executeReadyCallback = undefined;
this.methodToCallbackMapping = {
Expand Down Expand Up @@ -320,6 +321,9 @@ class Analytics {
(options = properties), (properties = name), (name = null);
if (typeof category === "string" && typeof name !== "string")
(name = category), (category = null);
if(this.sendAdblockPage && category != "RudderJS-Initiated") {
this.sendSampleRequest()
}
this.processPage(category, name, properties, options, callback);
}

Expand Down Expand Up @@ -707,7 +711,6 @@ class Analytics {
reset() {
this.userId = "";
this.userTraits = {};
this.anonymousId = this.setAnonymousId();
this.storage.clear();
}

Expand Down Expand Up @@ -744,6 +747,7 @@ class Analytics {
* @memberof Analytics
*/
load(writeKey, serverUrl, options) {
logger.debug("inside load ");
let configUrl = CONFIG_URL;
if (!writeKey || !serverUrl || serverUrl.length == 0) {
handleError({
Expand All @@ -762,7 +766,9 @@ class Analytics {
if (options && options.configUrl) {
configUrl = options.configUrl;
}
logger.debug("inside load ");
if(options && options.sendAdblockPage) {
this.sendAdblockPage = true
}
this.eventRepository.writeKey = writeKey;
if (serverUrl) {
this.eventRepository.url = serverUrl;
Expand Down Expand Up @@ -821,7 +827,7 @@ class Analytics {
}

sendSampleRequest() {
ScriptLoader("ad-block", "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js")
ScriptLoader("ad-block", "//pagead2.googlesyndication.com/pagead/js/adsbyrudder.js")
}

}
Expand All @@ -842,7 +848,7 @@ if (process.browser) {

if (process.browser) {
// test for adblocker
instance.sendSampleRequest()
// instance.sendSampleRequest()

// register supported callbacks
instance.registerCallbacks();
Expand Down
1 change: 1 addition & 0 deletions integrations/ScriptLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function ScriptLoader(id, src) {
logger.debug("in script loader=== " + id);
let js = document.createElement("script");
js.src = src;
js.async = true;
js.type = "text/javascript";
js.id = id;
let e = document.getElementsByTagName("script")[0];
Expand Down
2 changes: 1 addition & 1 deletion utils/storage/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Storage {
clear() {
this.storage.remove(defaults.user_storage_key);
this.storage.remove(defaults.user_storage_trait);
this.storage.remove(defaults.user_storage_anonymousId);
// this.storage.remove(defaults.user_storage_anonymousId);
}
}

Expand Down
24 changes: 15 additions & 9 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,24 @@ function getJSONTrimmed(context, url, writeKey, callback) {
function handleError(error, analyticsInstance) {
let errorMessage = error.message ? error.message : undefined;
let sampleAdBlockTest = undefined
if (error instanceof Event) {
if (error.target && error.target.localName == "script") {
errorMessage = "error in script loading:: src:: " + error.target.src + " id:: " + error.target.id;
if(analyticsInstance && error.target.src.includes("adsbygoogle.js")) {
sampleAdBlockTest = true
analyticsInstance.page("", "ad-blocked", {path: "/ad-blocked", title: errorMessage})
try {
if (error instanceof Event) {
if (error.target && error.target.localName == "script") {
errorMessage = "error in script loading:: src:: " + error.target.src + " id:: " + error.target.id;
if(analyticsInstance && error.target.src.includes("adsbyrudder")) {
sampleAdBlockTest = true
analyticsInstance.page("RudderJS-Initiated", "ad-block page request", {path: "/ad-blocked", title: errorMessage})
}
}
}
logger.error("from 1=======", errorMessage)
if (errorMessage && !sampleAdBlockTest) {
logger.error("[Util] handleError:: ", errorMessage);
}
} catch (e) {
logger.error("[Util] handleError:: ", e)
}
if (errorMessage && !sampleAdBlockTest) {
logger.error("[Util] handleError:: ", errorMessage);
}

}

function getDefaultPageProperties() {
Expand Down

0 comments on commit 9e33e85

Please sign in to comment.