setUserId use

352 views
Skip to first unread message

Seneschaux

unread,
Aug 3, 2015, 11:58:52 AM8/3/15
to Snowplow
Hi team,

I've put the following near the top of a page's <body>
hakaLayer('setUserId', 'Seneschaux');

but the user_id value is not seen/set in the log, etc.  ('hakaLayer' is declared in container tag)

Reading some threads here, is is possible some variation of this belongs (only) in the "page tracker" tag (configuration)?
Something like:
<!-- Snowplow starts plowing -->
<script type="text/javascript">
...
window.snowplow('trackPageView');
window.snowplow('setUserId', 'Seneschaux');
...
</script>
<!-- Snowplow stops plowing -->

This doesn't appear to effect outcome (not seen in GTM preview) either.

Does a GTM variable need to be used?  (the UserId value will be passed as a variable value -- hardcoded in above example(s))

I'm convinced I'm not using this setUserId capability correctly.  Any advice would be appreciated.

Alex Dean

unread,
Aug 3, 2015, 12:16:12 PM8/3/15
to Snowplow
The user_id will be attached to all events on the page which are tracked after the user_id is set - so this is what you want:

...
window.snowplow('setUserId', 'Seneschaux');
window.snowplow('trackPageView');
...

If you have events which don't have a user ID attached, then I'd add some debugging in GTM to verify the order in which you are invoking these Snowplow function calls.

A

--
You received this message because you are subscribed to the Google Groups "Snowplow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snowplow-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Co-founder
Snowplow Analytics
The Roma Building, 32-38 Scrutton Street, London EC2A 4RQ, United Kingdom
+44 (0)203 589 6116
+44 7881 622 925
@alexcrdean

Seneschaux

unread,
Aug 3, 2015, 1:19:16 PM8/3/15
to Snowplow
Hey Alex,

So, can use setUserId ONLY in the page tracker tag configuration as your syntax [window.snowplow()] implies.  (Does it have to be set in GTM?)
When I do this, I see the (hardcoded) value in the CF log. (not GTM)

As I don't want to hardcode this, how would I pass a variable value to the tag configuration? (as a GTM variable?) 

I would rather set, for example, just after the container tag.
So syntax like:
hakaLayer('setUserId', variable-name);

Is this possible/reliable?  (Again, assuming any setUserId use is not seen in GTM preview at its not an "event".  This true?)

S

Seneschaux

unread,
Aug 3, 2015, 7:53:30 PM8/3/15
to Snowplow
Hi Alex,

My sp.js ref. is within the page tracker tag in GTM.  (I believe this is done as per the docs)  I fear I'll have to reach out to other resources if I need to use a variable (in scope) holding the login name (as desired) for the UID

Can you confirm this is the ONLY way (inside GTM) to use 'setUserID'?  I've reviewed docs and tried window.snowplow() within header and body (and even tried using GTM variable; didn't expect that to work).

S

Seneschaux

unread,
Aug 4, 2015, 10:02:58 AM8/4/15
to Snowplow
Hi all,

Could use some tips on using setUserId.  Is the page tracker (All Pages trigger) GTM tag the only place to use it?

Seneschaux

unread,
Aug 5, 2015, 2:23:02 AM8/5/15
to Snowplow
Tried many variations but found the following somewhat productive.  Perhaps you can help me understand this outcome.
...
<body>
... 
<script type="text/javascript"> dataLayer = [{ 'userFirst-lastname':first-last, 'userEmail':myEmail, 'userAccount':org }];
alert(logId);
hakaLayer.push('setUserId', logId); </script>
...
Alert outcome looks as it should.  Using GTM, I see 3 messages but the Page Load data layer finishes as follows:
Data Layer values after this Message:
1
{
2
  0: 'm',
3
  1: 't',
4
  2: 'h',
5
  3: 'o',
6
  4: 'm',
7
  5: 'a',
8
  6: 's',
9
  7: '@',
10
  8: 'h',
11
  9: 'o',
12
  10: 't',
13
  11: 'm',
14
  12: 'a',
15
  13: 'i',
16
  14: 'l',
17
  15: '.',
18
  16: 'd',
19
  17: 'e',
20
  18: 'm',
21
  19: 'o',
22
  20: '1',
23
  userFirst-lastname: 'Matt Thomas',
24
  userEmail: 'mth...@hotmail.net',
25
  userAccount: 'Hotmail Demo1',
26
  event: 'gtm.load'
27
}


I 
I must be still doing something wrong but running out of ideas.

S

Seneschaux

unread,
Aug 5, 2015, 2:25:44 PM8/5/15
to Snowplow
Hi folks,

...
<body>
...
<script type="text/javascript"> dataLayer = [{ 'userFirst-lastname':first-last, 'userEmail':myEmail, 'userAccount':org }];
alert(logId);
dataLayer.push(['setUserId', logId]); </script>
...

In GTM, see 2 messages now and 2nd is
2
 
Message:
1
['setUserId', 'mtho...@hotmail.demo1'] 

Unfortunately I still don't see "&uid=" in the CF logs.  

Robert Kingston

unread,
Aug 7, 2015, 5:01:08 AM8/7/15
to Snowplow
Hi Seneschaux,

It sounds like you're confusing Google Tag Manager code with Snowplow code. This complicates things considerably for testing.

Try testing the code out as Alex suggested above and read up on how how Google Tag Manager works - it's a whole other kettle of fish. Simo Ahava's posts are generally pretty good: http://www.simoahava.com/analytics/variable-guide-google-tag-manager/

Cheers,
Rob

Seneschaux

unread,
Aug 7, 2015, 2:08:38 PM8/7/15
to Snowplow
Hi Rob,

Thanks for your feedback.  You're right, in that GTM was a bit of a learning curve so I am quite the noob in that regard.  I understand the sp.js is loaded on the page tracker event (GTM built-in All Pages trigger).  I tested Alex's code and and it appears to work for me when I send a hard-coded values.  Unfortunately, I'm struggling to acquire a variable's value to use inside the suggested window.snowplow() call within this page tracker tag configuration (Custom HTML).  I understand this is the "ideal" place to record user_id so, until I can use as directed, I'm simply asking if this is the "only place to set user_id".  (It's MUCH easier for me, at this time, to attempt the user_id assignment "after" the tracker and within the page "body".  I'm sensing this may not be possible.)

I've re-read Simo's post and wondering if the Javascript or Custom Javascript variable might help (in-concert with "All Pages" tag) but may be unnecessary given the page tracker tag configuration is Javascript already.  

Full disclosure: my goal is to Snowplow/GTM track within the Salesforce application.  Perhaps this greatly impacts configuration as the GTM tag container is actually in a Salesforce page "header".
I suspect this is a bit of an "ah-ha" moment to readers so apologize for leaving this out earlier.  Nevertheless, the triggers fire and I'm able to acquire all but the desired uid (user_id) in the CF logs.

I (nearly) regret Salesforce is used for our PoC (future use will include non-Salesforce sites) but pushing through the complexities in hopes alternative solutions exist.

Perhaps there is some experience using GTM/Snowplow with Salesforce and your team or readers can offer some advice?  

S

Alex Dean

unread,
Aug 7, 2015, 3:23:36 PM8/7/15
to Snowplow
Hi Seneschaux,

No direct experience integrating Snowplow -> GTM -> Salesforce I'm afraid.

I believe your goal is to track all Snowplow events with an associated user ID which is available from a JavaScript variable.

As a first step, please try something else:
  1. Fire a vanilla page view
  2. Write a GTM rule/trigger that waits for the user ID to be available to GTM, then calls setUserId, and then fires a Snowplow structured event
  3. Confirm that the Snowplow structured event has the user ID attached to it

Once you have this working, please reply in this thread.

Thanks,

Alex

Seneschaux

unread,
Aug 7, 2015, 5:47:52 PM8/7/15
to Snowplow
Hi Alex,

Thanks for your patience and understanding -- really appreciate this.

I attempted to implement your advice.
a. Created a Tag (Vanilla Page View) that fires on Page View and Event="userIdFound".  GTM variable "userId" defined.
b. Within site <body>, dataLayer = [{'event':'userIdFound', 'userId':userName,...
c. The "Vanilla Page View" tag type is Custom HTML executing " window.snowplow('setUserId', {{userId}}) "
d. I do see the userIdFound event fire in GTM but the "Vanilla Page View" does not fire. 

Perhaps I'm misunderstanding your instruction ("vanilla page view" or "waits for the user ID to be available to GTM") but still see no "&uid"= in the CF logs.  

Again, thanks for your patience.  Perhaps you can provide more detail?

S

Alex Dean

unread,
Aug 7, 2015, 7:17:50 PM8/7/15
to Snowplow
I think we need to go simpler. Try this:
  1. Write a GTM rule/trigger that waits for the user ID to be available to GTM, then executes a JavaScript alert containing the user ID

Once you have this working, reply to this thread.

A

Seneschaux

unread,
Aug 7, 2015, 8:49:04 PM8/7/15
to Snowplow
Hi Alex,

If I understand, I replaced the "Vanilla Page View" Tag's config with:
alert({{userId}})
//window.snowplow('setUserId', {{userId}})

No alert was seen.  Vanilla Tag was not fired. Let me know if you have other ideas or spot issues below



S

Alex Dean

unread,
Aug 8, 2015, 3:59:49 AM8/8/15
to snowpl...@googlegroups.com

Right - we've whittled your problem down to the point where it's a pure GTM problem. You can use GTM resources, forums etc to fix that.

Reply back in this thread when you've got this working and your problem is Snowplow-shaped again.

A

Seneschaux

unread,
Aug 8, 2015, 3:44:57 PM8/8/15
to Snowplow
Hi Alex,

I got it!  Critical notes:
1. Setting the user_id (setUserId) MUST be done in a GTM tag
2. That said, one must trigger the tag with an dataLayer.push({'event',...) to trigger the tag
3. Take care with variable names/typos as these will haunt you

Thanks much for your patience.

S

Alex Dean

unread,
Aug 8, 2015, 4:42:35 PM8/8/15
to Snowplow
Glad to hear you got it working!

A
Reply all
Reply to author
Forward
0 new messages