Skip to content

Commit

Permalink
Drop Google Analytics ecommerce. (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemijRodionov authored Feb 19, 2020
1 parent 95ea354 commit c4fe867
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 74 deletions.
9 changes: 0 additions & 9 deletions front/js/shared/tracking.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -64,7 +56,6 @@
});
mediator.subscribe('onSuccessOrder', (_, orderPositions, orderData) => {
yaTracker.purchase(orderPositions, orderData);
gaTracker.purchase(orderPositions, orderData);
});

DOM.$searchForm.submit(() => reachGoal('USE_SEARCH_FORM'));
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions shopelectro/selenium/analytics_goals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
97 changes: 35 additions & 62 deletions shopelectro/tests/tests_js_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
{
Expand All @@ -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,
Expand Down

1 comment on commit c4fe867

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on c4fe867 Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 759-e8d84e6c disappeared from front/js/shared/tracking.es6, that's why I closed #762. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.