diff --git a/front/js/shared/tracking.es6 b/front/js/shared/tracking.es6 index 1d409d78..af1c30a3 100644 --- a/front/js/shared/tracking.es6 +++ b/front/js/shared/tracking.es6 @@ -15,18 +15,10 @@ $purchasedOrder: $('.js-purchased-order'), }; - // @todo #759:60m Create tests for eCommerce tracking. - // Test all events, these perform tracking operations. - // Sync container for yaTracker window.dataLayer = window.dataLayer || []; const yaTracker = new YATracker(window.dataLayer, 'RUB'); // Ignore ESLintBear (no-undef) - // load google analytics scripts and enable ecommerce plugin - const loadedGa = loadGaTransport(); // Ignore ESLintBear (no-undef) - loadedGa('require', 'ecommerce'); - const gaTracker = new GATracker(loadedGa, 'ecommerce'); // Ignore ESLintBear (block-scoped-var) - const init = () => { setUpListeners(); }; @@ -64,7 +56,6 @@ }); mediator.subscribe('onSuccessOrder', (_, orderPositions, orderData) => { yaTracker.purchase(orderPositions, orderData); - gaTracker.purchase(orderPositions, orderData); }); DOM.$searchForm.submit(() => reachGoal('USE_SEARCH_FORM')); diff --git a/requirements.txt b/requirements.txt index c0e9ab9e..2d7248b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,4 +25,4 @@ sorl-thumbnail==12.5.0 python-telegram-bot==11.1.0 sentry-sdk==0.7.2 https://github.com/selwin/django-user_agents/archive/master.zip -https://github.com/fidals/refarm-site/archive/0.7.2.zip +https://github.com/fidals/refarm-site/archive/0.8.0.zip diff --git a/shopelectro/selenium/analytics_goals.py b/shopelectro/selenium/analytics_goals.py index 968b073b..c3a5bd09 100644 --- a/shopelectro/selenium/analytics_goals.py +++ b/shopelectro/selenium/analytics_goals.py @@ -42,8 +42,8 @@ def fetch(self): self.goals = self.driver.execute_script('return window.dataLayer.results;') def __getitem__(self, index: int): - return self.goals[index][0]['ecommerce'] + return self.goals[index][0] def __iter__(self): for g in self.goals: - yield g[0]['ecommerce'] + yield g[0] diff --git a/shopelectro/tests/tests_js_analytics.py b/shopelectro/tests/tests_js_analytics.py index d9925fce..6846ce4e 100644 --- a/shopelectro/tests/tests_js_analytics.py +++ b/shopelectro/tests/tests_js_analytics.py @@ -41,39 +41,6 @@ def last_order(self): return Order.objects.order_by('-created').first() -@tag('slow') -@helpers.disable_celery -@override_settings(DEBUG=True, INTERNAL_IPS=tuple()) -class GoogleEcommerce(Ecommerce): - - fixtures = ['dump.json'] - - def test_purchase(self): - self.buy() - order = self.last_order() - order_positions = order.positions.all() - reached = self.browser.execute_script('return gaObject.results;') - require, transaction, *positions, send = reached - - self.assertEqual(require, ['require', 'ecommerce']) - self.assertEqual( - transaction, - ['ecommerce:addTransaction', { - 'id': order.fake_order_number, 'revenue': order.revenue, - }], - ) - for pos, order_pos in zip(positions, order_positions): - self.assertEqual( - pos, - ['ecommerce:addItem', { - 'name': order_pos.name, - 'price': order_pos.price, - 'quantity': order_pos.quantity, - }], - ) - self.assertEqual(send, ['ecommerce:send', None]) - - @tag('slow') @helpers.disable_celery @override_settings(DEBUG=True, INTERNAL_IPS=tuple()) @@ -101,14 +68,16 @@ def get_goals(self) -> selenium.Goals: return goals def assert_add(self, product: Product, goal_position: int): # Ignore CPDBear - reached_goals = self.get_goals() - self.assertTrue(reached_goals) - reached = reached_goals[goal_position] + goals = self.get_goals() + self.assertTrue(goals) + reached = goals[goal_position] + self.assertEqual(reached['event'], 'addToCart') - self.assertIn('add', reached) - self.assertEqual(reached['currencyCode'], 'RUB') + ecommerce = reached['ecommerce'] + self.assertIn('add', ecommerce) + self.assertEqual(ecommerce['currencyCode'], 'RUB') - reached_detail = reached['add'] # Ignore CPDBear + reached_detail = ecommerce['add'] # Ignore CPDBear self.assertEqual( len(reached_detail['products']), 1, @@ -126,14 +95,17 @@ def assert_add(self, product: Product, goal_position: int): # Ignore CPDBear ) def assert_remove(self, product: Product, goal_position: int): - reached_goals = self.get_goals() - self.assertTrue(reached_goals) + goals = self.get_goals() + self.assertTrue(goals) + + reached = goals[goal_position] + self.assertEqual(reached['event'], 'removeFromCart') - reached = reached_goals[goal_position] - self.assertIn('remove', reached) - self.assertEqual(reached['currencyCode'], 'RUB') + ecommerce = reached['ecommerce'] + self.assertIn('remove', ecommerce) + self.assertEqual(ecommerce['currencyCode'], 'RUB') - reached_remove = reached['remove'] + reached_remove = ecommerce['remove'] self.assertEqual( len(reached_remove['products']), 1, @@ -152,20 +124,21 @@ def test_purchase(self): order = self.last_order() positions = order.positions.all() - reached_goals = self.get_goals() - self.assertTrue(reached_goals) + goals = self.get_goals() + self.assertTrue(goals) + self.assertEqual(goals[0]['event'], 'Purchase') - reached = reached_goals[0] - self.assertIn('purchase', reached) - self.assertEqual(reached['currencyCode'], 'RUB') + ecommerce = goals[0]['ecommerce'] + self.assertIn('purchase', ecommerce) + self.assertEqual(ecommerce['currencyCode'], 'RUB') - reached_purchase = reached['purchase'] + purchase = ecommerce['purchase'] self.assertEqual( - reached_purchase['actionField'], + purchase['actionField'], {'id': order.fake_order_number, 'revenue': order.revenue}, ) - for reached_pos, order_pos in zip(reached_purchase['products'], positions): + for reached_pos, order_pos in zip(purchase['products'], positions): self.assertEqual( reached_pos, { @@ -179,21 +152,21 @@ def test_product_detail(self): product = Product.objects.first() selenium.Product(self.browser, product.vendor_code).load() - reached_goals = self.get_goals() - self.assertTrue(reached_goals) - - reached = reached_goals[0] - self.assertIn('detail', reached) - self.assertEqual(reached['currencyCode'], 'RUB') + goals = self.get_goals() + self.assertTrue(goals) + self.assertEqual(goals[0]['event'], 'Detail') + ecommerce = goals[0]['ecommerce'] + self.assertIn('detail', ecommerce) + self.assertEqual(ecommerce['currencyCode'], 'RUB') - reached_detail = reached['detail'] + detail = ecommerce['detail'] self.assertEqual( - len(reached_detail['products']), + len(detail['products']), 1, ) self.assertEqual( - reached_detail['products'][0], + detail['products'][0], { 'id': product.id, 'name': product.name,