0

While creating the Targeting Rule Javascript Variable It asks me to create two variables:

  1. Global Variable Name
  2. Variable Name

Where we need to define that variable in our code file? I am having variable my_variable in my javascript declared and defined in between <head> tag before the google analytics code.

How I can show the experiment when my_variable is having value 10? Nothing else I need to match.

Note: I need only this Rule to be applied (only One).

enter image description here

VBMali
  • 1,360
  • 3
  • 19
  • 46

1 Answers1

2

Is the current var that are you looking for, for example in the following code is executed just before the Google Optimize's code. (in this case needs to be like this)

<script>
   var "my_var" : 10;
</script>
//optimize Code inserted via Gtag
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-118297712-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxx-1', { 'optimize_id': 'GTM-xxxx'});
</script>

In this case is my_var.

Is called gobal because it need that scope to be reachable on the tool, you can look more about the gobal scope in this thread. What is the scope of variables in JavaScript?.

Now on the interface i configure it like this (i like to add the type on the var name) enter image description here

And now it can be used enter image description here

Kemen Paulos Plaza
  • 1,560
  • 9
  • 18
  • can you please help me in the way that my variable name is `my_variable` and when it is available in between head tag. I want to implement Google Optimize. just to match the `my_variable` value. Do you implemented in Google Optimize? – VBMali May 15 '18 at 10:03