Answers.Body: <p>If you're using SEOmatic - no. It's built in that the GA doesn't get spat out for the preview. If you're using a regular template - yes; you may want to wrap your GA code in a conditional so that it's not spat out when requested via the live preview.</p>
  
  <pre><code>{% if not craft.config.devMode and not craft.request.isLivePreview %}{# GA code here #}{% else %}&lt;!-- Google Analytics script is NOT included in LivePreview or if devMode is on --&gt;{% endif %}
  </code></pre>
  
  <p>[edit] Whoops, saw the other half of your question. What is it about your set up that's stopping you doing this? Sounds more like an Analytics issue than a Craft one to me.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T11:09:58.107Z
Answers.Text: Thanks Matt! As I mentioned in this question, this is an option, it would just involve adding some extra conditionals into the JS to check if `ga` is defined before firing any custom events / page tracking.
Answers.UserDisplayName: Mike Vaux
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T08:46:59.770Z
Answers.LastActivityDate: 2016-10-06T08:46:59.770Z
Answers.UserDisplayName: Matt Wilcox
Body: <p>Will Google Analytics be recording page views / events from within a Live Preview? And if so, is there a way to prevent this from happening?</p>
  
  <p>My understanding is that with Google Analytics you can set the domain for which it should track (e.g. to prevent it trying to track any local build events etc), but I am presuming that the domain used for Live Preview views will be the same as as if a user was viewing the front end of the site?</p>
  
  <p>If it would track Live Preview views, I understand that an option for some people would be to wrap their GA code block in a conditional:</p>
  
  <p><code>{% if not craft.request.isLivePreview %}{# ga code here #}{% endif %}</code></p>
  
  <p>but because we have custom event tracking built into the JS, which therefore uses the global <code>ga</code> object, it would not be as simple in our case (though is still an option with a few checks for whether <code>ga</code> is defined).</p>
  
Tags: <live-preview><analytics>
Title: Does Google Analytics track Live Preview 'page views'?
ThreadText: # Does Google Analytics track Live Preview 'page views'?
  
  (Asked by: username_0 on 2016-10-06)
  
  Will Google Analytics be recording page views / events from within a Live Preview? And if so, is there a way to prevent this from happening?
  
  My understanding is that with Google Analytics you can set the domain for which it should track (e.g. to prevent it trying to track any local build events etc), but I am presuming that the domain used for Live Preview views will be the same as as if a user was viewing the front end of the site?
  
  If it would track Live Preview views, I understand that an option for some people would be to wrap their GA code block in a conditional:
  
  `{% if not craft.request.isLivePreview %}{# ga code here #}{% endif %}`
  
  but because we have custom event tracking built into the JS, which therefore uses the global `ga` object, it would not be as simple in our case (though is still an option with a few checks for whether `ga` is defined).
  
  **Tags:** live-preview, analytics
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-10-06. Score: 3 | Accepted answer
  
  If you're using SEOmatic - no. It's built in that the GA doesn't get spat out for the preview. If you're using a regular template - yes; you may want to wrap your GA code in a conditional so that it's not spat out when requested via the live preview.
  
  ```
  {% if not craft.config.devMode and not craft.request.isLivePreview %}{# GA code here #}{% else %}<!-- Google Analytics script is NOT included in LivePreview or if devMode is on -->{% endif %}
  
  ```
  
  [edit] Whoops, saw the other half of your question. What is it about your set up that's stopping you doing this? Sounds more like an Analytics issue than a Craft one to me.
  
  > **Comments:**
  > **username_0**: Thanks username_1! As I mentioned in this question, this is an option, it would just involve adding some extra conditionals into the JS to check if `ga` is defined before firing any custom events / page tracking.  
  
  ---
  
  