-
Notifications
You must be signed in to change notification settings - Fork 5
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
#759 google ecommerce #760
Changes from 4 commits
6f425d0
66b37ce
dd0aca1
18bdf8b
8f0bc7f
89ddfeb
92c13e7
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 |
---|---|---|
|
@@ -17,19 +17,8 @@ | |
|
||
// Sync container for yaTracker | ||
window.dataLayer = window.dataLayer || []; | ||
// Load ecommerce plugin for gaTracker | ||
try { | ||
ga('require', 'ecommerce'); // Ignore ESLintBear (block-scoped-var) | ||
} catch (e) { | ||
Sentry.captureException(e); // Ignore ESLintBear (no-undef) | ||
var ga = console.log; // Ignore ESLintBear (no-var) | ||
console.error(`GaTracker failed to load. Traceback: ${e}`); | ||
} | ||
|
||
const yaTracker = new YATracker(window.dataLayer, 'RUB'); // Ignore ESLintBear (no-undef) | ||
const gaTracker = new GATracker(ga, 'ecommerce'); // Ignore ESLintBear (block-scoped-var) | ||
|
||
// @todo #504:30m Send info about product's brand to YA and GA. | ||
const gaTracker = new PublishedGATracker(); // Ignore ESLintBear (block-scoped-var) | ||
|
||
const init = () => { | ||
setUpListeners(); | ||
|
@@ -78,6 +67,44 @@ | |
}); | ||
} | ||
|
||
// @todo #759:30m Move PublishedGATracker to a separate file. | ||
|
||
class PublishedGATracker { | ||
constructor() { | ||
this.published = false; | ||
} | ||
|
||
purchase(productsData, txData) { | ||
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. maybe it's possible to add tests for ecommerce behaviour. 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 will create todo for it |
||
const publishOnce = () => { | ||
// Publish only once | ||
if (this.published) return; | ||
|
||
// Load ecommerce plugin for gaTracker | ||
ga('require', 'ecommerce'); // Ignore ESLintBear (block-scoped-var) | ||
const tracker = new GATracker(ga, 'ecommerce'); // Ignore ESLintBear (block-scoped-var) | ||
|
||
tracker.purchase(productsData, txData); | ||
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. hope data is consistent with gAnalytics api docs. Looks too simple and suspicious =) 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. Data were consistent before, so what could be wrong? |
||
this.published = true; | ||
}; | ||
|
||
window.addEventListener('gtm_loaded', () => { | ||
try { | ||
publishOnce(); | ||
} catch (e) { | ||
Sentry.captureException(e); // Ignore ESLintBear (no-undef) | ||
console.error(e); | ||
} | ||
}); | ||
|
||
try { | ||
publishOnce(); | ||
} catch(e) { | ||
// Error occured because of unloaded Google tag manager. | ||
// `gtm_loaded` event will try to publish again. | ||
} | ||
} | ||
} | ||
|
||
function publishPurchase() { | ||
if (!DOM.$purchasedOrder.length) return; | ||
const orderData = { | ||
|
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.
provide doc plz why it's published, but not common
GATracker
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.
publish is not the most good name for classes purpose.
LimitedGATracher
orSafeGATracker
might be more good. Up to youThere 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.
I believe
LoadedGATracker
would be the best name