Skip to content
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

se#761 se#791 se#780 Create ga loader and move it to RF side #314

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ecommerce/front/trackers.es6
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,40 @@ class GATracker extends Tracker {
this.transport(`${this.name}:${actionName}`, data);
}
}


/**
* Reliable loader of Google Analytics scripts.
*
* Google Analytics scripts (GA) are loading by the Google tag manager (GTM).
* If GA is still not loaded, the function will delay execution until it is loaded.
*/
function loadGaTransport(onLoadName) {
var state = {
loaded: false,
delayed: [],
};

let load = () => {
ga('require', 'ecommerce');
state.loaded = true;
};

try {
load();
} catch (e) {
window.addEventListener(onLoadName, () => {
load();
// submit delayed transactions
state.delayed.forEach((args) => ga(...args));
});
}

return (...args) => {
if (state.loaded) {
ga(...args);
} else {
state.delayed.push(args);
}
};
}
6 changes: 6 additions & 0 deletions pages/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from functools import partial

from django.conf.urls import url
from django.urls import reverse

from pages import views
from pages.models import CustomPage
Expand All @@ -9,6 +10,11 @@

custom_page_url = partial(url, name=CustomPage.ROUTE)


def reverse_custom_page(name):
return reverse(CustomPage.ROUTE, kwargs={'page': name})


urlpatterns = [
url(r'^$', views.FlatPageView.as_view(), name='index'),
# /one/
Expand Down