Skip to main content

Google Analytics integration

Creating custom segments within Google Analytics

S
Written by Steve Jones
Updated over a week ago

Our Google Analytics and Google Tag Manager integrations allow you to send events directly into your Google Analytics account each time a user views or responds to your survey.

Please note:
Our Google Analytics integration only works with Grapevine Surveys that were created after January 10th 2024.

Surveys created before then are known as legacy single-question surveys and are not compatible with our Google Analytics integration. You can, however, recreate any of your older surveys, which will then automatically be compatible with our Google Analytics integration.

For this integration to work, you will need to have Google Analytics already set-up in your store.

Enabling Google Analytics for onsite/embedded surveys

If you're using Google Tag Manager, then an overview of how to set this up can be found in our article Sending events to Google Analytics using Google Tag Manager.

You can enable Google analytics via the Integrations page within the Grapevine Surveys app. Click on the More details button within the Google Analytics card:

On the next page, click the Enable Google Analytics Integration button:

The page will update to show that the integration has been enabled:

That's all you need to do to enable your onsite and embedded surveys to start sending events into Google Analytics.

Once enabled, our Script Tag will automatically detect your Google Analytics settings and will send events to your Google Analytics account every time a user views or submits a question from an onsite or embedded survey.

Read more about the events and data that we send.

Enabling Google Analytics for post-purchase surveys

If you have set-up post-purchase surveys and have added the Grapevine Survey app block to your Thank You Page, then you will need to map the Google Analytics events to the corresponding Shopify Analytics events.

Please note:

Unfortunately, surveys that appear on the Order Status Page are unable to send events to Google Analytics. Only surveys on the Thank You Page (the page that is shown once immediately after checkout) contains the data needed for the events.

You will either need to create a custom pixel within your Shopify Admin or, if you already have a custom pixel that loads the GA code and listens for other events, then you can modify that pixel to include the Grapevine Survey events.

Setting up the custom pixel for post-purchase surveys

We'll look at this as if you are creating a new custom pixel.

Create a new custom pixel from your Shopify Admin by going to Settings > Customer events

Click on the Add custom pixel button:

Give your custom pixel a name, e.g. Grapevine Surveys:

Put the following javascript code into the code block:

//Initialize GTM tag
var f = document.getElementsByTagName('script')[0];
var j = document.createElement('script');
j.async = true;
j.src='https://www.googletagmanager.com/gtag/js?id=G-XXX1234';
f.parentNode.insertBefore(j, f);

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXX1234');

analytics.subscribe("survey_viewed", event => {
gtag("event", "survey_viewed", {
survey_name: event.customData.survey_name,
survey_code: event.customData.survey_code,
});
});

analytics.subscribe("survey_answer", event => {
gtag("event", "survey_answer", {
survey_name: event.customData.survey_name,
survey_code: event.customData.survey_code,
question: event.customData.question,
question_code: event.customData.question_code,
answer: event.customData.answer,
});
});

analytics.subscribe("survey_completed", event => {
gtag("event", "survey_completed", {
survey_name: event.customData.survey_name,
survey_code: event.customData.survey_code,
});
});

Important:

You must replace G-XXX1234 within the code with your GA4 ID.

You can find your GA4 ID in GA4 by going to:

Google Analytics > Admin > Data collection and modification > Data Streams > Then click on the applicable stream for your online store and copy the MEASUREMENT ID value.

Once you have replaced the example GA4 ID in the code with your own GA4 ID, click Save at the the top of the page to save your custom pixel.

The Connect option will then become available. Click Connect and then read the warning in the dialogue box.
​
If you are happy to proceed, click Connect again:

That's it for the custom pixel. Your Grapevine Surveys events are now mapped from Shopify Analytics into Google Analytics:

Event data sent to Google Analytics 4 (GA4)

There are 3 different events, some of which fire more than once if the survey contains multiple questions.

Survey viewed event

This event is fired when the survey is presented on the page:

gtag('event', 'survey_viewed', {
'survey_name': {{survey_name}},
'survey_code': {{survey_code}},
});

Survey response event

This event is fired when the at least one question in the survey is answered by the respondent:

gtag('event', 'survey_response', {
'survey_name': {{survey_name}},
'survey_code': {{survey_code}},
});

Survey question answered event

This event is fired after each answer is provided:

gtag('event', 'survey_answer', {
'survey_name': {{survey_name}},
'survey_code': {{survey_code}},
'question': {{question.text}},
'question_code': {{question.code}},
'answer': {{answer}},
});

Survey completed

This event is fired if the respondent gets to the last question in the survey and answers it:

gtag('event', 'survey_completed', {
'survey_name': {{survey_name}},
'survey_code': {{survey_code}},
});

Event variable values

The variables that we send within the above events are based on your survey's settings and the answers provided by survey respondents.

Survey variables within each event

survey_name - This is the name that you have given to your survey within the Grapevine Surveys app. The survey name is not visible to the respondent.

survey_code - Each survey has it's own unique Survey Code. The code can be found at the top of the page when viewing the survey report within the Grapevine Surveys app:

survey_code.png

question.text - This is the text that you have configured as your question to the respondent:

survey_name.png

question.code - Each question in a multi-question enabled survey has it's own unique code. The code can be found at the bottom of the question when viewing the survey report:

why-did-you-shop.png

answer - In the case of a multi-question enabled survey, the answer is directly related to a question and it's value will be answer that has been provided by the respondent. In the case of a fixed response question, it will be the value of the dropdown or radio box selected. In the case of an open text survey, it will be the text entered by the respondent. In the case of an NPS question, this will be the numerical value of the rating submitted.

Please note:

For Google Tag Manager equivalent events, see Sending events to Google Analytics using Google Tag Manager.

Handling event data from multiple surveys

If you have multiple surveys published across your different sales channels all pushing events into Google analytics, then you will need a way to group and analyze the responses and impressions for each survey.

Each Grapevine survey has a unique Survey Code which allows you to create a segment for each survey that you have published:

survey_code.png

Analysing Survey Data in Google Analytics

Once you've enabled the Google Analytics integration, you will start to see the events being pushed into your GA account.

To view them, go to Behaviour > Events > Top Events and search through the list until you find your survey.

You can then click through to that event to view the Viewed Survey and Submitted Responses events.

Screenshot 2023-03-08 at 15.16.56.png

You can then use the GA secondary dimensions to take a closer look to see where those responses are coming from, what devices are being used to submit them and what the gender split is on responses and much more!

Screenshot 2023-03-08 at 15.12.24.png

Screenshot 2023-03-08 at 15.13.43.png

Screenshot 2023-03-08 at 16.00.09.png

Screenshot 2023-03-08 at 15.59.32.png

Need any help?

If you have any questions about the content of this article or any other Grapevine Surveys related question, then please do just get in touch.

Did this answer your question?