Analytics
2.2K members online now
2.2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Can we split GA code in two parts?

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

 

Can we split a Enhanced GA code in two parts, running half code (tracker + loading ecommerce plugin) in one script tag and then have some HTML code and then remaining part of GA code (ecommerce functions + send pageview). Like this

 

 

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('require', 'displayfeatures');
ga('require', 'ec');

</script>

Some HTML goes here
Some HTML goes here 
Some HTML goes here
Some HTML goes here 
<script>
ga('ec:addImpression', {'id': 'P12345', 'name': 'Android Warhol T-Shirt', 'category': 'Apparel/T-Shirts', 'brand': 'Google', 'variant': 'black', 'list': 'Search Results', 'position': 1 });
ga('ec:addImpression', {'id': 'P67890', 'name': 'YouTube Organic T-Shirt', 'category': 'Apparel/T-Shirts', 'brand': 'YouTube', 'variant': 'gray', 'list': 'Search Results', 'position': 2 });
ga('send', 'pageview');
</script>

Reason for doing this is that we could not dynamically generate product data in head section of the page.

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Hemant M
March 2017

Can we split GA code in two parts?

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆

Hey,


I would not recommend sending the Pageview later on. You might be loosing some hits.

But you could use an Event hit to send your Impression Data
See this Post: https://www.en.advertisercommunity.com/t5/Google-Analytics-Code/GA-Enhanced-Ecommerce-Send-Impressio...

Best regards

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Hemant M
March 2017

Can we split GA code in two parts?

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆

Hey,


I would not recommend sending the Pageview later on. You might be loosing some hits.

But you could use an Event hit to send your Impression Data
See this Post: https://www.en.advertisercommunity.com/t5/Google-Analytics-Code/GA-Enhanced-Ecommerce-Send-Impressio...

Best regards

Can we split GA code in two parts?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Hemant M
 
You can send impressions data with event hit. create event with 
 
ga("send","event","Ecommerce","Impression","Welcome page",{nonInteraction: true});
 

Best Reg
J